Please someone Help Me with Javascript Exercise Snail in the well. | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Please someone Help Me with Javascript Exercise Snail in the well.

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. Please assist how can i do it? function main() { var depth = parseInt(readLine(), 10); //your code goes here

14th Nov 2022, 11:39 AM
Pravesh Maharaj
Pravesh Maharaj - avatar
4 Answers
+ 3
What's your try? Learn about loops before After taking input, calculations are explained in day by day result already. Just follow. Print final Day value..
14th Nov 2022, 11:49 AM
Jayakrishna 🇮🇳
+ 2
So what can you do? Revise lessons again.. Observe example code carefully.. Try exercises after lessons to understand concepts more clearly.. Then you can attempt this easily.. That's the way to go for anyone.. understanding then Attempt is important than success first time... Happy learning.
14th Nov 2022, 12:03 PM
Jayakrishna 🇮🇳
+ 1
its very hard for me.
14th Nov 2022, 11:59 AM
Pravesh Maharaj
Pravesh Maharaj - avatar
+ 1
Pravesh Maharaj Try to make your own observations with different numbers then combine it into a logic. Make sure you remember the previous lessons
14th Nov 2022, 1:15 PM
I am offline
I am offline - avatar