nodeschool / discussions

:school::speech_balloon: need help with nodeschool? or just wanna ask a question? open an issue on this repo!
489 stars 107 forks source link

Javascript exercise for-loop. #2614

Open MarcoL10 opened 2 years ago

MarcoL10 commented 2 years ago

I have a problem with the exercise for-loop with JavaScripting. I mean I got the right result but just I don't understand why the result is 45. Can someone gently explain it to me ? How total become 45 ? Thanks in advance

flicksuper commented 2 years ago

i have the same problem, what does it mean?

Orevic64 commented 2 years ago

I can’t do it, how do I do it?

Waden03 commented 2 years ago

same problem

mzgdev commented 2 years ago

Hello people, if you have the correct result, your codes are something like this:

let total = 0
let limit = 10

for(let i = 0; i < limit; i++){
  total = total + i
}       

console.log(total) 

for each repetition, the previous value of the variable i is added for i between 0 and 10 the result is: 0+1+2+3+4+5+6+7+8+9 = 45

Esme6969 commented 2 years ago

have no clue