(Solved)I wonder, the answers sum = 9 if depth =42, how about you guys? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

(Solved)I wonder, the answers sum = 9 if depth =42, how about you guys?

function main() { var depth = parseInt(readLine(), 10); //your code goes here sum = 0 j = 0 for(i=0; j < depth; i++){ j = j+5 sum += 1 } console.log(sum) }

7th Feb 2021, 3:46 AM
Ratna13
Ratna13 - avatar
2 Answers
+ 2
Variable <i> is not necessary here, so we can safely remove it. Maybe this snippet can explain where <sum> got its value. function main() { var depth = 42; var sum = 0; for (var j = 0; j < depth; j += 5) { console.log(j); sum += 1; } console.log(sum); }
7th Feb 2021, 4:41 AM
Ipang
+ 1
I see, thank you 🙏🙏🙏. So, var i adds extra number 😇
7th Feb 2021, 5:58 AM
Ratna13
Ratna13 - avatar