JavaScript Simplified / Chapter 2 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 is the keyword that you use to declare a variable? let ^let$
The following statement is correct only if the variable has already been _______. userName = "buddy5000"; declared ^declared$
In a single statement, declare the variable pal and assign the string "Al" to it. let pal = "Al"; ^ *letpal=•Al•;$
Declare a variable without assigning it a value. Make up the variable's name. let username; ^let.*;$
Assign a string to a variable. Make up the string and the variable. The variable hasn't already been declared. let username = "bo55"; ^let.*=•.*•;$
The following statement has already been coded. Assign the variable a new string. Make up the string. let friend = "Charlie"; friend = "Bess"; ^friend=•.*•;*$
Declare a variable without assigning it a value. Then, in a second statement, assign it a string. Make up everything. let x;
x = "blue";
^let(.*);[\r\n]\1=•.*•;$
In a single statement, declare a variable without assigning it a value. Then assign it a string. Make up the variable and the string. Code an alert, specifying the variable, not the string, as the message. let name;
name = "John";
alert(name);
let(.*);[\r|\n]\1=•.*•;[\r|\n]alert\(\1\);
  1. Replace the asterisks with two statements.
  2. The first statement declares a variable and assigns it a string.
  3. The second statement displays the string in an alert. Use the variable, not the string, in the alert statement.
  4. Click the Result button (or, after revising, don't click, just wait).
  5. Wait a moment.
  6. If you've coded correctly, an alert will display the string.
  7. Dismiss the alert by clicking OK.
  8. For help with this code, see Chapter 2 in the book.
  1. I've coded a statement declaring a variable without assigning it a value. Leave this statement intact.
  2. Replace the asterisks with two statements.
  3. The first statement assigns your name to the variable.
  4. The second statement displays your name in an alert. Use the variable, not the string, in the alert statement.
  5. Click the Result button (or, after revising, don't click, just wait).
  6. Wait a moment.
  7. If you've coded correctly, an alert will display your name.
  8. Dismiss the alert by clicking OK.
  9. For help with this code, see Chapter 2 in the book.