Loops
Loops
π¨βπΌ Let's practice a simple
for loop by building a numbered list.π¨ Open
and:
- Create
exhibitLabelsstarting as an empty string - Use a
forloop to append labels for exhibits1through5 - Each label must be exactly
Exhibit Nfollowed by a newline (\n), including a trailing newline after exhibit 5
Required exports
exhibitLabels
Completion criteria
exhibitLabels must equal exactly (note the final \n):'Exhibit 1\nExhibit 2\nExhibit 3\nExhibit 4\nExhibit 5\n'
How a for loop works
for (let i = 0; i < limit; i++) {
// repeat work
}
Each part of the loop has a job:
- Initializer (
let i = 0) runs once before the loop starts - Condition (
i < limit) is checked before each iteration - Final expression (
i++) runs after each iteration
i++ means "add 1 to i." It's the same as i += 1.π MDN - for statement
π MDN - for...of (an alternative loop syntax you'll see in the wild)


