0

[SOLVED] There are some problem in my code. Please help!

***The Snail in the Well*** The snail climbs up 7 feet each day and slips back 2 feet each night. How many days will it take the snail to get out of a well with the given depth? Sample Input: 31 Sample Output: 6 Explanation: Let's break down the distance the snail covers each day: Day 1: 7-2=5 Day 2: 5+7-2=10 Day 3: 10+7-2=15 Day 4: 15+7-2=20 Day 5: 20+7-2=25 Day 6: 25+7=32 So, on Day 6 the snail will reach 32 feet and get out of the well at day, without slipping back that night. https://code.sololearn.com/ctrADT3m7j2i/?ref=app /////////////// function main() { var depth = parseInt(readLine(), 10); //your code goes here var feet = depth var i = 0 while(feet >= 0){ feet -= 5 i++ } console.log(i) } /////////////

29th Aug 2021, 5:14 PM
mesarthim
mesarthim - avatar
2 Réponses
+ 3
function main() { var depth = parseInt(readLine(),10); //your code goes here var feet = 0 var i = 0 while(1){ feet += 7; i++; if(feet >= depth){ break; } else{ feet-=2; } } console.log(i) }
29th Aug 2021, 5:20 PM
Abhay
Abhay - avatar
+ 1
Thanks a lot Abhay :)
29th Aug 2021, 5:41 PM
mesarthim
mesarthim - avatar