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))

5th Aug 2021, 9:27 PM
Olorunsogo Abiodun Isaac
Olorunsogo Abiodun Isaac - avatar
5 Answers
+ 2
I value after for loop is executed will be 4 . And 4*4=16%3=1
5th Aug 2021, 9:33 PM
Abhay
Abhay - avatar
+ 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.
5th Aug 2021, 9:43 PM
Abhay
Abhay - avatar
+ 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
5th Aug 2021, 9:56 PM
DHANANJAY PATEL
DHANANJAY PATEL - avatar
0
But the answer it showed me was 2
5th Aug 2021, 9:35 PM
Olorunsogo Abiodun Isaac
Olorunsogo Abiodun Isaac - avatar