For Loop in JavaScript

Level 348 keystrokes

This loops from 1 to 5 and outputs each number.

JavaScript code

// for (init; condition; update): i starts at 1 and the loop runs while i <= 5
// i++ adds 1 to i after each iteration
1for (let i = 1; i <= 5; i++) {
// Runs 5 times with i = 1, 2, 3, 4, 5
2 console.log(i);
3}

Output

1
2
3
4
5
Practice typing this code

Practice typing this code. Results are not recorded in the rankings.

Symbols in this code

The symbols you type in this JavaScript code and how often they appear.

  • ;× 3
  • (× 2
  • )× 2
  • +× 2
  • =× 2
  • .× 1
  • {× 1
  • }× 1
  • <× 1

More JavaScript examples at level 3

← JavaScript typing practice