0
How to enter a number and make the sum of all previous numbers, EXAMPLE: I enter the number 5, it will add up to 0+1+2+3+4 = 10 ! He will add and give the answer.
I have to use the FOR command.
My command has gone like this, but it’s not correct.
function somatoria(x){
var soma = 0;
for(var i = 0; i < x; i++) {
soma = i + i;}
return soma;
}
Tries
soma += i
– Sam
soma = soma + i;
or, simplifying,soma += i
– Costamilam
The only difference for this one is that it goes 2 in 2 and here goes in 1, which in this part is already right.
– Maniero
It worked out guys, so much that I messed up the code, I gave this shot, plus Brigadeo, people.
– Vinicius
It just doesn’t make sense to start the variable
i
of the tie with0
, since 0 does not change the result. Then it could bevar i = 1
.– Sam
Function somatoria(x){ var soma = 0; for(var i = 0; i < x; i++) { soma = sum + i;} Return soma; }
– Vinicius