- Navigate to this directory in your terminal.
- Run
npm install --global jestto install the testing library (if you've already done this, skip this step!). - Preferably in a full-screen terminal, run
jest --watch-allto start testing.
You'll be working in main.test.js this time!, creating the variables needed with the values asked for, according to the specifications given in the tests. Check your terminal for feedback on which aspect of the problem you have yet to complete, and read the specifications' actual code implementation for extra help; it makes explicit exactly what outputs are expected given the test inputs.
- Please do not call the functions; just declare them! You can call them for your own testing purposes, but then either delete or comment out the line.
- If you are asked to define a variable in terms of another, do not recalculate the value of that variable. For example, if x = 5, and y = 6, and z is supposed to be x + y, do NOT set z to equal 11 directly, or say that y should be 5 + 6. Use the variables instead.
Let's start by creating our variables so that we can manipulate them later on with functions.
- Create a variable called
xand set it to the value 3. - Create a variable called
yand set it to the value 10. - Create a variable called
zand set it to the value 5. - Create a variable called
nameand set it the string version of your first name. - Create a variable called
greetingand set it to the value'HEY'.
Now for some functions!
- Create a function called
multiplythat takes in one parameter and changesxto the product ofxand that parameter. - Create a function called
modYBythat takes in one parameter, dividesyby that parameter, and setsyto the remainder of that division. Look up the JavaScript modulus operator if you don't remember it, because it could sure come in handy here! - Create a function called
oppositethat takes in a parameter and setszto equal the opposite sign of that parameter. For example, if the function is passed6,zshould be set to-6, and if passed-85,zshould be set to85. Note that we are not "reading" the value ofzhere. In other words, unlike the other problems here, it doesn't matter whatzused to be! - Create a variable called
makeFullNamethat takes in a string parameter and setsnameto have that string at the end, with a space in the middle. - Create a function called
yellAtthat takes in a string parameter and adds that string to the end ofgreeting, with a comma and a space in between and an exclamation point at the end. This string concatenation (or "smooshing" in the technical parlance) should be set to be the new value ofgreeting.