Use do...while with a false condition and show how many times the body ran.
Acceptance criteria
- 1.#out should show 1.
JavaScript Tutorial · JavaScript Loops
These 10 tasks go with the JavaScript do while Loop chapter. 5 of them ask you to build something small from scratch; 5 give you code that is already broken and ask you to work out why. Set aside about 90 minutes for the whole set, though you can do them in any order.
Nothing here is marked by a person. When you press Submit, the editor checks your code against the points listed under each task and tells you straight away what passed and what didn't (you need a free account to submit). If you get stuck, there are hints, and a worked solution once you've had a go. The first 2 tasks are free; the rest are part of the practice plan.
If it's been a while since you read the chapter, here is how it starts: “The JavaScript do while loop runs a block of code at least once, then repeats it while a condition is true.” .
1.Run at least onceexercise · easy · 10 min
Use do...while with a false condition and show how many times the body ran.
Passes when: #out should show 1.
2.Count to threeexercise · easy · 10 min · practice plan
Use do...while to collect 1,2,3.
Passes when: #out should show 1,2,3.
3.Add until over tenexercise · easy · 10 min · practice plan
Keep adding 4 until the total passes 10, then show the total.
Passes when: #out should show 12.
4.Double until largeexercise · easy · 10 min · practice plan
Start at 3 and double until above 20.
Passes when: #out should show 24.
5.Compare with whileexercise · medium · 10 min · practice plan
A while loop with a false condition runs zero times — show that count.
Passes when: #out should show 0.
6.Fix the loop that skips the first passbug fix · easy · 8 min
A plain while never runs here; do...while should run once.
Passes when: #out should show 1.
7.Fix the missing increment guardbug fix · easy · 8 min · practice plan
The condition uses the wrong bound and stops too early.
Passes when: #out should show 1,2,3.
8.Fix the inverted exit testbug fix · easy · 8 min · practice plan
The condition is reversed, so the loop stops after one pass.
Passes when: #out should show 12.
9.Fix the wrong operatorbug fix · easy · 8 min · practice plan
Adding instead of doubling gives the wrong result.
Passes when: #out should show 24.
10.Fix the counter placed after the checkbug fix · easy · 8 min · practice plan
The count is read before the loop updates it.
Passes when: #out should show 3.
Between them these tasks cover do...while and Guaranteed first pass.
Looking for a different chapter? See every practice set, or switch to the interview theory questions.