0

Javascript

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? Pls, some should help me My trial=> for (i=7; i<=42, i=i+7-2) { document.write(i) }

5th Feb 2021, 8:52 AM
Emmanuel Olofinmoyo
4 ответов
+ 2
Instead of using a step of 5, you should do the forth and back separately, because there is a case that the snail just get out of the well when it moves forth, in this case, in the last iteration, there is no back of 2.
5th Feb 2021, 11:17 AM
Gordon
Gordon - avatar
+ 1
If you want to use while loop: while (p < depth){ p += 7; days++; if(p>=depth){ break; } p -= 2; }
5th Feb 2021, 12:09 PM
CLAD
CLAD - avatar
0
for( var i=0;i<depth; i++){ if(s>=depth || s>=depth-2 ){ break; } s=s+g-t ; //5//10//15//20//25//30//35//40 These are some necessary changes that you should bring to your code
5th Feb 2021, 9:01 AM
Atul [Inactive]
0
Thanks
5th Feb 2021, 9:06 AM
Emmanuel Olofinmoyo