0
Saw this question today in challenge and i need someone to tell me the answer because i got a different answer from sololearn
function calc(i) { return (i*i) % 3;} for(var i = 1; i < 4; ++i) { } console.log(calc(i))
4 Respostas
+ 2
I value after for loop is executed will be 4 . And 4*4=16%3=1
+ 2
I'mabiodun i ran the code in code playground and it shows me 1 . If the answer was 2 then you can report that question.
+ 2
I'mabiodun
sum = 0;
function calc(i) { return (i*i)%3;}
for(var i = 1; i < 4; ++i) {
sum += calc(i);
console.log(calc(i));
}
console.log(sum);
missing statement should be body of the for loop.
Result:
1 * 1 => 1 % 3 = 1
2 * 2 => 4 % 3 = 1
3 * 3 => 9 % 3 = 0
sum = 1 + 1 + 0 = 2
so the final answer is 2
DHANANJAY PATEL
0
But the answer it showed me was 2