+ 1

let total = 0, count = 1; while (count <= 10) { total += count; count += 1; } console.log(total);

Why is total = 55?

8th Nov 2020, 6:51 AM
Kayode Kolade Christopher
Kayode Kolade Christopher - avatar
3 RĂ©ponses
+ 9
while loop is making sum of numbers from 1 to 10 as value of count is from 1 to 10. Value is getting add to total resulting in 55. 1+2+3+4+...+10 = 55 Therefore answer is 55.
8th Nov 2020, 7:05 AM
ツSampriya😘ツ
ツSampriya😘ツ - avatar
+ 5
your loop in practice making the sum 1+2+...+10 which result is 55
8th Nov 2020, 7:00 AM
KrOW
KrOW - avatar
0
The author of Eloquent JavaScript helped me understand this one when he said this block of code could look like this: console.log(sum(range(1,10))); if we happened to have convenient operations like sum and range available.
16th Sep 2022, 6:51 AM
KelliBre