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.
- Initialize a variable
counterto the value ofstartValue. - Write a
do-whileloop:- Inside the
doblock:- Print: "Loop body executed."
- Increase the
counterby 1.
- The loop condition should check if
counteris less thanthreshold.
- Inside the
01EXAMPLE 1
Input
startValue = 100Output
Logs: "Loop body executed."Explanation: Runs once, then fails condition 101 < 10.
02EXAMPLE 2
Input
startValue = 8Output
Logs: "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
JavaScriptSystem handles I/O — write your function only
Loading...
3 Hidden
Input Arguments
startValue100
threshold10
Expected Output
Loop body executed.
Click RUN to test your solution