JavaScript Loops

  1. Create a blank, valid HTML5 document.
  2. Create a JavaScript file
  3. Solve each of the given problems, writing a loop the outputs the given output to the JavaScript console.

Example

Problem:

0 1 2 3 4 5 6 7 8 9 10

Output in the console:

0
1
2
3
4
5
6
7
8
9
10

Solution

for (i = 0; i <= 10; i++) {
  console.log(i);
}

Problems

The output of the problems is written on a single line for brevity; your solutions will output each value on a new line like in the example above.

  1. 0 100 200 300 400 500 600 700 800 900 1000
  2. 1 2 4 8 16 32 64 128
  3. 0 2 4 6 8 10
  4. 3 6 9 12 15
  5. 9 8 7 6 5 4 3 2 1 0
  6. 1 1 1 2 2 2 3 3 3 4 4 4
  7. 0 1 2 3 4 0 1 2 3 4 0 1 2 3 4