Coffee School Loops

Code Editor

for(var i = 1; i <= 20; i++) { // do something here }

Preview

Console Log:

Loops

Time to complete: 5 minutes

##Goal: Repeating code

Another commonly used construct is a loop, to repeat code multiple times. For example:

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

will output the numbers 0 to 9.

Now write a loop to output the numbers 0 to 9 multiplied by 2, ie 0, 2, 4…