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

Code the short way of writing x = x + 1; Use either of the two legal expressions. x++; or ++x; (x\+\+)|(\+\+x);?
Code the short way of writing x = x - 1; Use either of the two legal expressions. x--; or –x; (x--)|(--x);?
In a single statement, increment the variable num and assign its new value to a second variable, newNum, which hasn't been declared beforehand. let newNum = ++num; letnewNum=\+\+num;
In a single statement, decrement num and assign its original value to newNum, which hasn't been declared beforehand. let newNum = num--; letnewNum=num--;
Using minimal code, decrement x. Use either of the two legal expressions. x--; or --x; (x--)|(--x);
What is the long version of x++? x = x + 1; x=x\+1;
In a single statement subtract 1 from a variable and assign the new value to another variable, which hasn't been declared beforehand. Both variables wind up with the same value. Make up both variable names. let newNum = --num; let[a-z_$][a-zA-Z0-9_$]*=--[a-z_$][a-zA-Z0-9_$]*;
In a single statement add 1 to a variable and assign its original value to another variable, which hasn't been declared beforehand. Make up both variable names. let newNum = num++; let[a-z_$][a-zA-Z0-9_$]*=[a-z_$][a-zA-Z0-9_$]*\+\+;
  1. Assign a number to a variable that hasn't been declared earlier.
  2. Decrement the variable using minimal code. Use either of the two legal expressions.
  3. Display the new value in an alert.
  4. Click the Result button (or, after revising, don't click, just wait).
  5. Wait a moment.
  6. If you've coded correctly, the decremented value will display.
  7. Dismiss the alert by clicking OK.
  8. For help with this code, see Chapter 6 in the book.
  1. Assign a number value to a variable that hasn't been declared previously.
  2. Increment the variable using minimal code while assigning its incremented value to a second variable. Both variables wind up with the same value.
  3. Display the value of the second variable in an alert.
  4. Click the Result button (or, after revising, don't click, just wait).
  5. Wait a moment.
  6. If you've coded correctly,
  7. Dismiss the alert by clicking OK.
  8. For help with this code, see Chapter 6 in the book.