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);
6 Réponses
+ 3
I =-2 assigns -2.
Correct way is i -= 2
Remove return (count); // no need.
count start from 0.
+ 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
+ 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..
+ 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.
0
Still show execution time out
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 🥺