JavaScript Simplified / Chapter 41 Exercises

  • Index of exercises
  • Email me

1

2

3

4

5

6

7

8

9

10

Congratulations. You've aced all the exercises for this chapter.


To practice on your own, or to check code you believe shouldn't have been scored as incorrect, go to CodePen.


Are you ready to rate JavaScript Simplified? on Amazon?


Rate it on Amazon.

0,1,2,3,4,5,6,7,8,9

0

0

0

0

The keyword that rounds a number to a specified number of decimal places and converts it to a string is _____. toFixed toFixed
A number modified by toFixed isn't a number. It's a ______. Answer with 1 word. string string
Code a statement that rounds num's value to 4 places, and assigns it to strNum, which hasn't been declared beforehand. let strNum = num.toFixed(4); letstrNum=num\.toFixed\(4\);
Code a statement that rounds num's value to 0 places, and assigns it to strNum, which hasn't been declared beforehand. let strNum = num.toFixed(); letstrNum=num\.toFixed\(\);
Code a statement that rounds n to 3 places, and assigns it to dec3, which hasn't been declared beforehand. let dec3 = n.toFixed(3); letdec3=n\.toFixed\(3\);
Code a statement that rounds num to 0 places, and assigns it to intStr, which hasn't been declared beforehand. let intStr = num.toFixed(); letintStr=num\.toFixed\(\);
Code a statement that rounds a number represented by a variable and assigns it to another variable, which hasn't been declared beforehand. Make up the variable names and the number of decimal places. let nStr = n.toFixed(2); let[a-z_$][a-zA-Z0-9_$]*=[a-z_$][a-zA-Z0-9_$]*\.toFixed\([1-9][0-9]*\);
Code a statement that rounds a number represented by a variable to 0 places, and assigns it to the same variable. num = num.toFixed(); ([a-z_$][a-zA-Z0-9_$]*)=\1\.toFixed\(\);
  1. Assign a number with many decimal places to a variable.
  2. Code an alert that displays the number rounded to 2 decimal places.
  3. Click the Result button (or, after revising, don't click, just wait).
  4. Wait a moment.
  5. If you've coded correctly, an alert will display the number rounded to 2 places.
  6. Dismiss the alert by clicking OK.
  7. For help with this code, see Chapter 41 in the book.
  1. Assign a number with many decimal places to a variable.
  2. Code an alert that displays the number rounded to 0 decimal places.
  3. Click the Result button (or, after revising, don't click, just wait).
  4. Wait a moment.
  5. If you've coded correctly, an alert will display the number rounded to 0 places.
  6. Dismiss the alert by clicking OK.
  7. For help with this code, see Chapter 41 in the book.