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

What keyword specifies a statement or statements to be executed when all tests above have failed? else else
What are the keywords that test for a condition when an if test has failed? else if elseif
Code an else statement that displays an alert saying "Incorrect". else {
  alert("Incorrect");
}
else{[\r\n]alert\(•Incorrect•\);[\r\n]}
Code an else if statement that tests whether a has the same value as b. If so, display an alert that says "OK". else if (a === b) {
  alert("OK");
}
elseif\(a===b\){[\r\n]alert\(•OK•\);[\r\n]}
Code an else statement that assigns the value of one variable to another. Make up the variable names. else {
  num2 = num1;
}
else{[\r\n][a-z_$][a-zA-Z0-9_$]*=[a-z_$][a-zA-Z0-9_$]*;[\r\n]}
Code the first line of a statement, that, if tests above it fail, checks whether one variable doesn't equal another. Make up the variable names. else if (a !== b) { elseif\([a-z_$][a-zA-Z0-9_$]*!==[a-z_$][a-zA-Z0-9_$]*\){
Code an if statement that tests whether a variable's value is greater than or equivalent to another variable's value. If so, display an alert. If not, display a different alert. Make up everything. if (a >= b) {
  alert("OK");
} else {
  alert("Not OK");
}
if\([a-z_$][a-zA-Z0-9_$]*>=[a-z_$][a-zA-Z0-9_$]*\){[\r\n]alert\(•.*•\);[\r\n]}else{[\r\n]alert\(•.*•\);[\r\n]}
Code an if statement that tests whether a variable's value is less than another variable's value. If so, display an alert. If not, test whether the first variable's value is greater than the second variable's value. If so, display a different alert. Make up everything. if (a < b) {
  alert("Smaller");
} else if (a > b) {
  alert("Bigger");
}
if\(([a-z_$][a-zA-Z0-9_$]*)<([a-z_$][a-zA-Z0-9_$]*)\){[\r\n]alert\(•.*•\);[\r\n]}elseif\(\1>\2\){[\r\n]alert\(•.*•\);[\r\n]}
  1. Code an if statement: If 1 is equivalent to 2 (it can't be), display an alert.
  2. Otherwise, display a different alert.
  3. Click the Result button (or, after revising, don't click, just wait).
  4. Wait a moment.
  5. If you've coded correctly, the second alert will display.
  6. Dismiss the alert by clicking OK.
  7. For help with this code, see Chapter 14 in the book.
  1. Code an if statement: If 1 is equivalent to 2 (it isn't, of course), display an alert.
  2. Otherwise, if 2 is equivalent to 2, display a different alert.
  3. Click the Result button (or, after revising, don't click, just wait).
  4. Wait a moment.
  5. If you've coded correctly, the second alert will display.
  6. Dismiss the alert by clicking OK.
  7. For help with this code, see Chapter 14 in the book.