The while loop
Watch it run · 1 of 3
Counting digits of 345
1let n = 345;2let digits = 0;3while (n > 0) {4 n = Math.floor(n / 10);5 digits++;6}7console.log(digits);
Memory
number n
345
Output
(nothing yet)line 1Start with 345.
step 1 of 8
Watch it run · 1 of 3
1let n = 345;2let digits = 0;3while (n > 0) {4 n = Math.floor(n / 10);5 digits++;6}7console.log(digits);
Memory
number n
345
Output
(nothing yet)line 1Start with 345.