+ 3

I don't know what I'm getting wrong here. Getting a "No output" error.

function main() { var depth = parseInt(readLine(), 10); //your code goes here var y = 0; while (dist <= depth) { dist += 7 y++; if (dist <= depth) { dist -= 2 } else { return y; console.log(y); } } }

15th Mar 2022, 3:24 AM
Milan Kurienov
7 Answers
+ 4
Your code is giving no output because you've ended the main function using return before console.log. So before the interpreter executes console.log, the main() function is terminated and hence, cause no output. So you can use return statement after console.log. The other thing which causes error is that you haven't declared the dist variable. So, you have to declare the dist variable like your declared y variable. Happy Coding šŸ¤ 
15th Mar 2022, 3:58 AM
Adil
Adil - avatar
+ 3
Raju I don't think that he need to call the main function because it will run automatically in node js. Because I think he is doing code coach. Right Milan Kurienov ? And I think in code coach readline also works šŸ¤”
15th Mar 2022, 4:34 AM
Adil
Adil - avatar
+ 2
Adil Yes, you are right if it is running in code coachšŸ˜…
15th Mar 2022, 5:06 AM
Raju Adhikary
Raju Adhikary - avatar
+ 2
Milan Kurienov In line 11 if(dist <= depth) instead of using "<=" only use "<"
15th Mar 2022, 5:39 AM
Raju Adhikary
Raju Adhikary - avatar
+ 2
Oh thanks
15th Mar 2022, 5:43 AM
Milan Kurienov
+ 1
You need to call main() function then you will get another error with readline the answer is already discussed in sololearn https://www.sololearn.com/discuss/2866976/?ref=app Then you will get another error with dist variable and return statement that already said by Adil .
15th Mar 2022, 4:07 AM
Raju Adhikary
Raju Adhikary - avatar
0
Thanks a lot for the help, it works mostly now, except for one of the tests. Here's whats happening now: function main() { var depth = parseInt(readLine(), 10); //your code goes here var y = 0; var dist = 0; while (dist <= depth) { dist += 7 y++; if (dist <= depth) { dist -= 2 } else { console.log(y) return y; } } } When I input 42, it outputs 9, while the correct answer is 8. I have no idea why thats happening and it's working with the other inputs
15th Mar 2022, 5:25 AM
Milan Kurienov