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

Type the ternary operator. ? \?
? is the ________ operator. ternary ternary
What character replaces else in the shorthand version? : :
In the following code, feedback is "yes" if answer === "tail", no if it's something else. Fill in the blank. let feedback = answer === "tail" ? ____________________; "yes" : "no" •yes•:•no•;?
The statement is testing whether answer is "tail". Fill in the blank. let feedback __________________ "yes" : "no"; = answer === "tail" ? =answer===•tail•\?
Rewrite the following code using the shortcut. let feedback;
if (answer === "tail") {
  feedback = "yes";} else {
  feedback = "no";
}
let feedback = answer === "tail" ? "yes" : "no"; letfeedback=answer===•tail•\?•yes•:•no•;
Assign 0 to x if y === 0. Otherwise assign 1 to x. x wasn't previously declared. Use the shortcut. let x = y === 0 ? 0 : 1; letx=y===0\?0:1;
Write a shortcut to if...else using nothing but variables. No numbers, no strings. Make up everything. let x = y === z ? a : b; let[a-z_$][a-zA-Z0-9_$]*=[a-z_$][a-zA-Z0-9_$]*===[a-z_$][a-zA-Z0-9_$]*\?[a-z_$][a-zA-Z0-9_$]*:[a-z_$][a-zA-Z0-9_$]*;
  1. I've coded a ternary operator for a conditional statement and commented it out. Below my code, replace the asterisks with the ternary code translated into an if statement.
  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 "Correct!"
  5. Dismiss the alert by clicking OK.
  6. For help with this code, see Chapter 15 in the book.
  1. I've coded an if statement and commented it out. Below my code, replace the asterisks with the if statement translated into ternary code.
  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 "Incorrect".
  5. Dismiss the alert by clicking OK.
  6. For help with this code, see Chapter 15 in the book.