- 2
Snail problem
Every day the snail crawls 7 feet up and every night it goes down 2 feet. How many days will it take for a snail to climb to the specified height?
4 Answers
+ 5
Alim Niyazov Where is your attempts?
+ 3
https://code.sololearn.com/cCpc2SlHCnBS/?ref=app
Here's something similar using recursion
+ 3
function climb() {
var height = parseInt(readLine(), 10);
let days = 0;
if (height<= 0) return days;
for (let i = 0; ; i -= 2) {
i += 7;
++days;
if (i >= height) break;
i -= 2
}
return days;
}
console.log(climb(days));
+ 1
I just don't understand what's wrong with my code?