Giter Club home page Giter Club logo

week0.day3.notsorandom's Introduction

week0.day3.notSoRandom

Instructions

  1. Create a Repo on GitHub named "notSoRandom"
    • Remember to initialize it with a README.md
  2. In command line, navigate to your “Documents” Folder:
    • Clone the repo to your computer using git clone {url}
  3. Inside of this repo, create a file called “notSoRandom.js”
  4. Inside of this file, create the following 5 functions:
    • random - takes 1 number argument and console.logs a random integer between 0 and the given number (exclusively)
      random(10); // 4
      random(100); // 78
      random(2); // 0
    • randomLetter - takes 1 string argument and console.logs a random letter from the given string
      randomLetter("blah"); // "b"
      randomLetter("abcdefg"); // "g"
      randomLetter("z"); // "z"
    • myGuy - takes 1 string argument and console.logs the same string with “, my guy.” at the end of it
      myGuy("Take it easy"); // "Take it easy, my guy"
    • string_N_times - takes 2 arguments, a string and a number, and console.logs the string as many times as the given number
    • hypotenuse - takes 2 number arguments (corresponding to the perpendicular sides of a right triangle) and console.logs the length of the 3rd side, the hypotenuse.
    • NOTE: don’t worry about the math! Here’s the equation and some links to helpful functions in JavaScript
    hypotenuse(3,4); // 5
  5. Be sure to test to see if your functions are working as expected by calling them at the end of your script and running the node notSoRandom.js command in your console.
  6. Remember to add, commit, and push your changes!

Extra Credit

  • Look up how to set default parameter values for functions in JavaScript
    • Default values allow functions to work even when the function is called without arguments
    • Provide default values (choose whatever values you’d like!) for each parameter in the functions you’ve made
  • At the other extreme, sometimes a function is given too many arguments. Look up the arguments array for functions in JavaScript.
    • All arguments are pushed into a default array called arguments that only exists within the scope of the function
    • For each of the functions we made, if the function is called with extra arguments, throw a message informing the user “Too many arguments given!”
  • JavaScript is considered a “weak typing” language, meaning data is not checked for being the correct TYPE of data.
    • For example, in the myGuy function we expect it to be called with a string argument, but what if a number is given? Try it out! This is not the intended behavior!
    • For each function, verify that each parameter is the correct type of data BEFORE executing the rest of the code. Throw a TypeError if it isn’t.

Helpful Resources

week0.day3.notsorandom's People

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

Forkers

justinasc5mlb

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.