JavaScript Simplified / Chapter 12 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 are the first 4 characters of an if statement? if ( if\(
What character ends the first line of an if statement? { {
Code the first line of an if statement that tests whether the variable teammates has the value of 8. if (teammates === 8) { if\(teammates===8\){
Type the last line of an if statement. } }
Type the incorrect character you see here. if (x = y) { = =
Following is the first line of an if statement. Code the next line. If the condition is true, display an alert that says, "Hi, John". Don't worry about indenting. if (firstName === "John") { alert("Hi, John"); alert\(•Hi,John•\);
Code the first line of an if statement that tests whether one variable has the same value as another. Make up the variable names. if (firstName === nickname) { if\([a-z_$][a-zA-Z0-9_$]*===[a-z_$][a-zA-Z0-9_$]*\){
Code the first line of an if statement that tests whether a variable has the value of a particular string. Make up the variable name and the string. if (gender === "female") { if\([a-z_$][a-zA-Z0-9_$]*===•.*•\){
  1. Code an if statement that tests whether a number equals itself. If the condition is true (it will be), display a congratulations alert.
  2. Click the Result button (or, after revising, don't click, just wait).
  3. Wait a moment.
  4. If you've coded correctly, the congratulations message will display in an alert.
  5. Dismiss the alert by clicking OK.
  6. For help with this code, see Chapter 12 in the book.
  1. Code a prompt asking for your first name.
  2. Code an if statement that tests whether the name you entered is identical to your actual first name. (Of course it is! "Mark" is identical to "Mark".) If the condition is true (it will be), display an alert that greets you by name.
  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 greet you by name.
  6. Dismiss the alert by clicking OK.
  7. For help with this code, see Chapter 12 in the book.