Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Dog Years Activity Did you know that eight (8) years in a human's life is like forty-five (45) years in a dog's life! How old
Dog Years Activity Did you know that eight (8) years in a human's life is like forty-five (45) years in a dog's life! How old would you be in dog years? The calculation is as follows: - The first two human years of a dog's life count as 10.5 dog years each - Each human year following counts as 4 dog years Instead of performing the calculations in your head, let's create a program. 1) Create a variable named myAge, and set it equal to your age as a number. Write a comment that explains this line of code. 2) Create a variable named earlyYears and save the value 2 to it. Note, the value saved to this variable will change. Write a comment that explains this line of code. 3) Use the multiplication assignment operator to multiply the value saved to earlyYears by 10.5 and reassign it to earlyYears. 4) Since we already accounted for the first two years, take the myAge variable, and subtract 2 from it. Set the result equal to a variable called laterYears. We'll be changing this value later. Write a comment that explains this line of code. 5) Multiply the laterYears variable by 4 to calculate the number of dog years accounted for by your later years. Use the multiplication assignment operator to multiply and assign in one step. Write a comment that explains this line of code. 6) If you'd like to check your work at this point, print earlyYears and laterYears to the console. Are the values what you expected? Check off this task when you're ready to move on. 7) Add earlyYears and laterYears together, and store that in a variable named myAgelnDogYears. Write a comment that explains this line of code. 8) Let's use a string method next. Write your name as a string, call its built-in method .toLowerCase(), and store the result in a variable called myName. The toLowerCase method returns a string with all lowercase letters. Write a comment that explains this line of code. You may need to research the tolowerCase() method. 9) Write a console.log statement that displays your name and age in dog years. Use string interpolation to display the value in the following sentence: Replace NAME with myName and AGE with myAgelnDogYears in the sentence above. Write a comment that explains this line of code. All, how did you do? 10) Modify the script so that instead of writing to the console, the results display in the webpage
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started