+ 1
Why does this code output 0 0?
let depth = 42; let days = 0; let climbed = 0; for (; climbed < depth; days ++) { climbed += 5; if (climbed = depth) { console.log(days); break; } } console.log(days) https://code.sololearn.com/W9VEemHtDpmJ/?ref=app https://code.sololearn.com/W9VEemHtDpmJ/?ref=app
6 ответов
+ 1
No, no it is not, the other problem is you are trying to overwork the poor 🐌😢. According to your algorithm, the snail will have to travel an extra day. What did that poor 🐌😢 ever do to you?😉
He can climb 7ft in a day and slides down 2ft when he takes a rest at night. What is 35 + 7? In other words, you need to check if the little fella has reached his goal(42ft) before you subtract 2ft for his resting.
-btw The code snippet you wrote does not match the code you linked.
+ 6
Take a closer look at the if statement. Are you trying to asign or compare?
+ 2
Thanks. I just saw it now. Is that the only problem?
+ 2
I have solved the problem. That was I code I wrote before getting it correctly. I was just wondering why it was outputting 0 0. It's my first time asking questions on this platform. I didn't know how to do it right. I'm sorry and thank you for your help
+ 2
if (climbed = depth) {
console.log(days)
days = 0
So console.log(days);
//output 0
+ 1
I'm glad to hear that, and you are welcome.