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

Rewrite this using camelCase. let Nameofband; let nameOfBand; letnameOfBand;
Declare a variable, in camelCase, whose name combines the words top player followed by the only legal non-letter, non-number character that isn't the underline_. let topPlayer$; lettopPlayer\$;
Declare a three-character variable using a lowercase letter, an uppercase letter, and a number. Don't assign a value. Make up the letters and the number. let aB1; let[a-z][A-Z][0-9];
In a single statement declare a legally-named variable and assign a number to it. Make up the variable name and the number. let aNum = 40; let[a-z_$][a-zA-Z0-9_$]*=[-]?(?:[.]\d+|\d+(?:[.]\d*)?);
In a single statement declare a legally-named variable and assign to it the sum of 2 other legally-named variables. let newNum = num1 + num2; let[a-z_$][a-zA-Z0-9_$]*=[a-z_$][a-zA-Z0-9_$]*\+[a-z_$][a-zA-Z0-9_$]*
Declare a variable that is a combination of your first and last names. Use camelCase. Don't assign a value. You can make up the names if you like. let markMyers; let[a-z]+[A-Z][a-z]*;
In a single statement declare a variable and assign it a number. let num = 1.038; let[a-z_$][a-zA-Z0-9_$]*=[-]?(?:[.]\d+|\d+(?:[.]\d*)?);
Code an alert using a variable inside the parentheses. alert(greetingToWorld); alert\([a-z_$][a-zA-Z0-9_$]*\);
  1. Replace the asterisks with three statements.
  2. The first statement declares a variable whose name is your first and last names combined, in camelCase.
  3. The second statement assigns the variable your first and last names, as a string.
  4. The third statement displays an alert, specifying the variable, not the string, as the message.
  5. Click the Result button (or, after revising, don't click, just wait).
  6. Wait a moment.
  7. If you've coded correctly, your name displays in an alert.
  8. Dismiss the alert by clicking OK.
  9. For help with this code, see Chapter 4 in the book.
  1. Replace the asterisks with three statements.
  2. The first statement declares a variable that combines an alphabet letter, a number, and both of the legal characters that are neither an alphabet letter nor a number.
  3. The second statement assigns a string to the variable.
  4. The third statement displays an alert, specifying the variable, not the string, as the message.
  5. Click the Result button (or, after revising, don't click, just wait).
  6. Wait a moment.
  7. If you've coded correctly, the string displays in an alert.
  8. Dismiss the alert by clicking OK.
  9. For help with this code, see Chapter 4 in the book.