+ 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
7 ответов
+ 6
Okay what have you attempted so far?
+ 3
Take another variable, sum, set it to zero, and add to that instead.
+ 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
+ 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
+ 1
1 (+2) 3 (+3) 6 (+4) 10
do you see the pattern?
+ 1
before the for loop,
declare a variable, named sum, assign 0 to it.
in the for loop, sum equals sum plus i.
0
Thanks for the help, I made the code.
And sorry for my english I need practice