0

Find the error please.

function main() { var depth = parseInt(readLine(), 10); //your code goes here count = 1; for(let i = 0;i < depth;i += 7) { if(i < depth){ i =- 2; } count++ ; } return (count); } console.log(count);

29th Nov 2022, 12:31 PM
Divya Kaushal
6 Answers
+ 3
I =-2 assigns -2. Correct way is i -= 2 Remove return (count); // no need. count start from 0.
29th Nov 2022, 12:57 PM
Jayakrishna 🇮🇳
Jayakrishna 🇮🇳 - avatar
+ 2
Define count on outside the function.. var count; It is because if you define count inside function it's scope only inside the function. This is we called Local variable. So to become it global define outside the function. Happy Learning 😍 Thank you
29th Nov 2022, 12:38 PM
Sâñtôsh
Sâñtôsh - avatar
+ 1
function main() { var depth = parseInt(readLine(), 10); //your code goes here var count = 0; for(let i = 0; i < depth; i += 7) { if(i < depth) i -= 2; count++ ; } console.log(count); } // corrected code .. compare with your... // declared inside, outside functions are different scopes..
29th Nov 2022, 1:09 PM
Jayakrishna 🇮🇳
Jayakrishna 🇮🇳 - avatar
+ 1
Divya Kaushal Instead of pasting the code, include a link to it in the question description. This way, we can see exactly as it is, and also run, see the problem, and test solution. Also, pls always inform the exact error message. It means a lot.
30th Nov 2022, 2:46 AM
Emerson Prado
Emerson Prado - avatar
0
Still show execution time out
29th Nov 2022, 12:50 PM
Divya Kaushal
0
var count = 0; function main() { var depth = parseInt(readLine(), 10); //your code goes here for(let i = 0;i < depth;i += 7) { if(i < depth) i -= 2; count++ ; } } console.log(count); Still have error 🥺
29th Nov 2022, 1:05 PM
Divya Kaushal