5 hands-on exercises and 5 find-the-bug challenges for the JavaScript Nested Loops lesson. Every one is checked automatically in the browser — write the code, run it, and the tests tell you what still fails.
Count how many times the inner code runs for a 3 by 4 pair of loops.
Add every number in the grid together and show the total.
Build 3 rows of stars, where row 1 has one star. Join the rows with a dash.
Pair every name with every city and count how many pairs there are.
Count each pair of numbers only once by starting the inner loop after the outer one.
Both loops use i, so the inner loop overwrites the outer one.
The inner loop starts above its limit, so nothing is added.
Ready to write the code?
The editor, the automatic checks and the worked solutions open up with an account.
Open the workspaceThe row string carries over, so every row keeps the stars before it.
A break in the inner loop was meant to skip, not to end the pairing early.
The inner loop starts at zero, so every pair is counted twice.