While Loops
A while loop repeats as long as its condition is true. Make sure something
changes each pass or it'll loop forever!
let i = 3;
while (i > 0) {
i--; // moves toward the exit
}
Your task
Write countdown(n) that returns an array [n, n-1, β¦, 1] using a while
loop. If n is 0 or less, return [].
β‘ 30 XP
π§± Code blocks
Drag a block into the editor, or tap it to drop it in where your cursor is. Add them in order to build your answer.
solution.jsRuns in your browser
Loading editorβ¦
Tests3 to pass
countdown(3)
countdown(0)
countdown(1)
Run your code to check these.