Javasript question 2

Hi guys
ive been doing questions on eloquent javascript and im currently stuck on fizzbuzz. i dont want help answering the question ill figure it out myself

I was looking through my notes and i found this program
let total = 0 , count = 1;

while(count <= 100){

total += count;

count += 1;

}

console.log(total);
//55

my question is why is the answer 55 here

if anyone can help break it down for me i want to understand why 55 is the answer

I dont want to be able just do the question by finding the answer online but i want to understand it

Any help would be great as i want to understand why
-Eleandro

1 Like

I think the answer is not 55, running the code deliver another result:

let total = 0
let count = 1;

while(count <= 100){
console.log('counters', count, total)
total += count;

count += 1;
}

console.log(total);
//55

Each iteration, total add his value plus count, and count increase 1 each iteration, the console message i added show you each of the iteration operations. Although, one of the iterations, total value is 55.

Any other question please post it :nerd_face:

Carlos Z