thecodezone.
The Code Zone
Short steps, at your pace · Free lessons and practice · Member video walkthroughs
Save your next small win.

Checking your account…

12.06 · Loop challenges & review / Practice · 5 min

Perform the first check

A diagnostic never ran because its repeat limit was zero. Make the required first check happen.

Activity 6 of 7 in Loop challenges & review

All courses

JavaScript Basics / 12.06

Perform the first check

Not started

Make one required check before considering repeat limits.

More options
Rob presses a diagnostic robot button and watches one lamp glow.
Rob’s comic strip · Loop challenges & review

Compare checks before and after a loop body

Work through 3 focused steps. Read the explanation, type each requested change and check it before moving on. Your own code carries forward.

The mini-lesson opens in a new tab. Your own code carries forward; each step has a focused check and an optional hint.

Start mini-lesson(opens in a new tab)

3 steps · Saved work · Instant feedback

YOUR TURN

Perform the first check

Perform a required diagnostic check once, then repeat only while attempt is within limit. Keep limit = 0 and the counter update. Convert the while loop to do/while so it prints Check 1 once even when no repeats are allowed. Do not add an extra console.log outside the loop.

Expected output
Check 1

Keep the starting inputs. Print these lines in this order, without extra output.

Edit JavaScript, then run it. Check Challenge shows which output checks pass or need a fix. Word wrap is enabled.

Ready to checkRun the checks to see your results here.

Work in VS Code instead

Copy the starter into a file named practice.js in VS Code. If Node.js is installed, open the terminal in that folder and run node practice.js. Compare the output with the task above. Automated challenge checks are available in the browser editor.

Code example
example.jsjavascript · example
const limit = 0;
let attempt = 1;
while (attempt <= limit) {
  console.log("Check " + attempt);
  attempt++;
}

Need a nudge?

Move the first check

A while loop checks before its first body execution. do/while places the condition after the body.

Keep the counter moving

Increment attempt inside the body. End the trailing while (attempt <= limit) with a semicolon.

Reveal a possible solution
One possible solution
example.jsjavascript · example
const limit = 0;
let attempt = 1;
do {
  console.log("Check " + attempt);
  attempt++;
} while (attempt <= limit);

Try limits 1 and 3. Expect one check for limit one, and checks 1 through 3 for limit three. Zero still runs once because the condition is checked after the first body execution.

Replace your editor code?

Your current work will be replaced. Choose Cancel to keep it.

Ready to try it?

Practice in your browser and see your results.

Progress details

Have a question?

Ask the Code Zone community.

Ask a question in The Code Zone (opens in a new tab)

Continue learning

ONE STEP FORWARD

Use do/while when the first pass is required, then check whether to repeat.