0

Question in snail in the well proplem using Javascript I tried a lot of time but I couldn't,and what is the problem in this code

var c =0; var i=0; var depth = parseInt(readLine(), 10); function count() { //your code goes here while(c+7<depth){ c =c+5; i++; } while(c+7>=depth){ c =c+7; i++; } } count(); console.log(i);

27th Jul 2021, 4:54 PM
AHMED MOHAMMED ELHASSAN AHMED
AHMED MOHAMMED ELHASSAN AHMED - avatar
10 Antworten
+ 4
There's an another method. When you don't want to use loop, You can give it a try: function main() { var depth = parseInt(readLine(), 10); //your code goes here console.log(Math.round(depth/5)) } But, in the hint, they told to use loop, so use loop. In addition, just know it buddy😉, it will help you in any other coding 🙂 Happy learning 💐
28th Jul 2021, 7:04 AM
Sowmiyashree S
Sowmiyashree S - avatar
+ 2
Can you post the challenge description or the link here.?
27th Jul 2021, 4:57 PM
RKK
RKK - avatar
+ 2
Don't mark my answer as best yet, it has not even answered the main question.
27th Jul 2021, 5:11 PM
RKK
RKK - avatar
+ 1
Brief Algorithm: c = 0 // snail progress d = 0 // count day while(1) d = d + 1 // increase the day c = c + 7 // increase(climb) by 7 daytime if c >= depth then // if the snail crosses the wall print(day) // here's your answer break // to kill infinite loop c = c - 2 // decrease(slip) by 2 nighttime
27th Jul 2021, 5:21 PM
RKK
RKK - avatar
+ 1
oops, typo it's 2 ~LoneWolf thank you :)
27th Jul 2021, 5:30 PM
RKK
RKK - avatar
0
I can't share but it is in conditional and loops in javascript course
27th Jul 2021, 5:01 PM
AHMED MOHAMMED ELHASSAN AHMED
AHMED MOHAMMED ELHASSAN AHMED - avatar
0
The snail slips by 2 at night.
27th Jul 2021, 5:17 PM
RKK
RKK - avatar
0
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.
27th Jul 2021, 5:17 PM
RKK
RKK - avatar
0
OK what is wrong with my code
27th Jul 2021, 5:19 PM
AHMED MOHAMMED ELHASSAN AHMED
AHMED MOHAMMED ELHASSAN AHMED - avatar
0
RKK Thanks I get it
27th Jul 2021, 5:32 PM
AHMED MOHAMMED ELHASSAN AHMED
AHMED MOHAMMED ELHASSAN AHMED - avatar