JavaScript Simplified / Chapter 38 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

Fill in the blank to round up. let roundedNum = ___________(numWithDecimal); Math.ceil Math\.ceil
What is the value of roundedNum? let roundedNum = Math.floor(1.9); 1 1
Round up origNum and assign it to roundNum, which hasn't been declared beforehand. let roundNum = Math.ceil(origNum); letroundNum=Math\.ceil\(origNum\);
Round down origNum and assign it to roundNum, which hasn't been declared beforehand. let roundNum = Math.floor(origNum); letroundNum=Math\.floor\(origNum\);
Round a variable's number to the nearest integer. Assign the result to a second variable that hasn't been declared beforehand. Make up the variable names. let newNum = Math.round(numWithDecimal); let[a-z_$][a-zA-Z0-9_$]*=Math.round\([a-z_$][a-zA-Z0-9_$]*\);
Round down a variable's number and assign the result to a second variable that hasn't been declared beforehand. Make up the variable names. let newNum = Math.floor(numWithDecimal); let[a-z_$][a-zA-Z0-9_$]*=Math\.floor\([a-z_$][a-zA-Z0-9_$]*\);
Round up a variable's number and assign the result to a second variable that hasn't been declared beforehand. Make up the variable names. let newNum = Math.ceil(fractional); let[a-z_$][a-zA-Z0-9_$]*=Math\.ceil\([a-z_$][a-zA-Z0-9_$]*\);
Round .00001 to 1 and assign it to a variable that hasn't been declared beforehand. Make up the variable name. let num = Math.ceil(.00001); let[a-z_$][a-zA-Z0-9_$]*=Math\.ceil\(\.00001\);
  1. In a single statement round a number with a decimal to the nearest integer and display it in an alert.
  2. Click the Result button (or, after revising, don't click, just wait).
  3. Wait a moment.
  4. If you've coded correctly, an alert will display the integer.
  5. Dismiss the alert by clicking OK.
  6. For help with this code, see Chapter 38 in the book.
  1. In a single statement round down a negative number with a decimal and display it in an alert.
  2. Click the Result button (or, after revising, don't click, just wait).
  3. Wait a moment.
  4. If you've coded correctly, an alert will display a negative integer.
  5. Dismiss the alert by clicking OK.
  6. For help with this code, see Chapter 38 in the book.