+ 1

I need to make a partial sum with the Loop for or while in Javascript

I need to add 1 + 2 + 3 + 4 + 5 ... N. And that my final iteration is <= 100

9th Feb 2020, 1:10 AM
Acxel Molina
Acxel Molina - avatar
7 Answers
+ 6
Okay what have you attempted so far?
9th Feb 2020, 1:12 AM
👑 Prometheus 🇸🇬
👑 Prometheus 🇸🇬 - avatar
+ 3
Take another variable, sum, set it to zero, and add to that instead.
9th Feb 2020, 1:18 AM
HonFu
HonFu - avatar
+ 1
It is the structure of the for cycle, for example for (i = 1; i <= 100; i ++) { document.write (i); } But I really have no idea how I can add to i
9th Feb 2020, 1:18 AM
Acxel Molina
Acxel Molina - avatar
+ 1
Ok, what I need is for example: Iteration 1 = 1 Iteration 2 = 3 Iteration3 = 6 Iteration3 = 10 Etc ... Until the value of i <= 100
9th Feb 2020, 1:27 AM
Acxel Molina
Acxel Molina - avatar
+ 1
1 (+2) 3 (+3) 6 (+4) 10 do you see the pattern?
9th Feb 2020, 2:15 AM
Denise Roßberg
Denise Roßberg - avatar
+ 1
before the for loop, declare a variable, named sum, assign 0 to it. in the for loop, sum equals sum plus i.
9th Feb 2020, 4:13 AM
Gordon
Gordon - avatar
0
Thanks for the help, I made the code. And sorry for my english I need practice
10th Feb 2020, 4:24 AM
Acxel Molina
Acxel Molina - avatar