- Navigate to this directory in your terminal.
- Run
npm install --global jestif you have not yet done so to install the testing library. - Preferably in a full-screen terminal, run
jest --watch-allto start testing.
You'll be working in main.test.js, creating the variables and functions needed, according to the specifications given in the Tasks section below. Check your terminal for feedback on which aspect of the problem you have yet to complete!
- Please do not call the functions; just declare them! You can call them to check for your own testing purposes, but then either delete or comment out the line. (Because our test code runs your function and modifies the global variables, checking if the variable has been changed to the value we'd expect, if you're calling your function and changing it ALSO, the test code will change the value a second time and, when it goes to check the value, it will not be what the test code is expecting.)
- 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, andy = 6, andzis supposed to be the sum ofx+y, do NOT setyto equal11directly. Use thexandyvariables directly in that calculation instead.
Let's start by creating our variables so that we can manipulate them later on with functions. Create those variables at the top of your file, OUTSIDE of any functions.
- Create a variable named
xand assign to it the value3. - Create a variable named
yand assign to it the value10. - Create a variable called
zand assign to it the value of4. - Create a variable called
greetingand assign to it the string 'hello'. - Create a variable called
firstNameand assign to it the string of your name. - Create a variable called
callStatusand assign to it the string 'ringing'.
Now let's make these variables useful by writing some functions!
- Create a function named
doubleand have it double the value ofx. - Create a function named
tripleand have it triple the value ofy. - Create a function named
squareand have it square the value ofz. - Create a function named
beNiceand have it change the value of greeting to the string 'hello' plus your name using the value of the variablefirstName. You can include other characters if you wish to make it look like a nice sentence. - Create a function named
changeNameand have it change the value offirstNameto the string 'Danger'. - Create a function named
hangUpand have it change the value ofcallStatusto the string 'call ended'.