JavaScript do while Loop — exercises and bug fixes
5 hands-on exercises and 5 find-the-bug challenges for the JavaScript do while Loop lesson. Every one is checked automatically in the browser — write the code, run it, and the tests tell you what still fails.
Exercises(5)
- 1
Run at least once
easy10 minUse do...while with a false condition and show how many times the body ran.
- 2
Count to three
easy10 minUse do...while to collect 1,2,3.
- 3
Add until over ten
easy10 minKeep adding 4 until the total passes 10, then show the total.
- 4
Double until large
easy10 minStart at 3 and double until above 20.
- 5
Compare with while
medium10 minA while loop with a false condition runs zero times — show that count.
Find the bug(5)
- 1
Fix the loop that skips the first pass
easy8 minA plain while never runs here; do...while should run once.
- 2
Fix the missing increment guard
easy8 minThe condition uses the wrong bound and stops too early.
- 3
Fix the inverted exit test
easy8 minThe condition is reversed, so the loop stops after one pass.
- 4
Fix the wrong operator
easy8 minAdding instead of doubling gives the wrong result.
- 5
Fix the counter placed after the check
easy8 minThe count is read before the loop updates it.
Ready to write the code?
The editor, the automatic checks and the worked solutions open up with an account.
Open the workspace