+ 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); } } }
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 đ€
+ 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 đ€
+ 2
Adil Yes, you are right if it is running in code coachđ
+ 2
Milan Kurienov In line 11 if(dist <= depth) instead of using "<=" only use "<"
+ 2
Oh thanks
+ 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 .
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