First, look at the example code in joinStrings-example.js. Try and predict what the console.log output will be. When you're ready, run the test:
npm test joinStrings-example.spec.jsIf you saw anything unexpected, feel free to review the code again.
After understanding the example code, you will recreate the snippet on your own using the following instructions (in joinStrings.js):
-
Create 4 variables:
firstName,lastName,thisYear, andbirthYear -
Create a 5th variable,
greeting, that is constructed from the previous 4 variables
- It should contain a greeting that includes the person's full name and age
Note: To make the tests pass, you will need to use exact values and wording (as you will see described in joinStrings.js). If the tests fail, look at the feedback in your terminal then check your spacing, capitalization, and punctuation.
You will edit your code to make it easier to read using the following instructions:
- Create 2 new variables:
fullNameandage
- Do NOT simply type the full name and age into the new variables
- Instead, use the pre-existing variables, with the calculations that are currently inside of
greeting
- Edit the
greetingstring to usefullNameandageinstead of the other 4 variables
greetingshould look something like:
"Hello! My name is " + fullNameRun all the tests one last time to ensure that the output remains unchanged:
npm test joinStrings.spec.js-
Look at the docs for JavaScript variables for a quick reference.
-
Refer back to the Variables and Operators lesson if you are still stuck.