+ 1
let total = 0, count = 1; while (count <= 10) { total += count; count += 1; } console.log(total);
Why is total = 55?
3 Antworten
+ 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.
+ 5
your loop in practice making the sum 1+2+...+10 which result is 55
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.