The Defiant Guardian

EasyAcc. 98.9%
+15 XP 5

First Contact

Unlike a standard while loop that checks the gate BEFORE entering, a do-while loop enters first and asks questions LATER. This means the code inside the do block is guaranteed to run at least once, even if the condition is already false.

The Assignment

Your function receives parameters startValue and threshold.

  1. Initialize a variable counter to the value of startValue.
  2. Write a do-while loop:
    • Inside the do block:
      • Print: "Loop body executed."
      • Increase the counter by 1.
    • The loop condition should check if counter is less than threshold.

01EXAMPLE 1

InputstartValue = 100
OutputLogs: "Loop body executed."

Explanation: Runs once, then fails condition 101 < 10.

02EXAMPLE 2

InputstartValue = 8
OutputLogs: "Loop body executed." (twice)

Explanation: Runs for 8 and 9, then fails at 10.

Constraints

  • Use a do-while loop structure.
  • Log message must match exactly.
LoopsControl FlowFundamentals
JavaScript
Loading...
3 Hidden

Input Arguments

startValue100
threshold10

Expected Output

Loop body executed.

Click RUN to test your solution