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) }
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.
+ 1
If you want to use while loop:
while (p < depth){
p += 7;
days++;
if(p>=depth){
break;
}
p -= 2;
}
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
0
Thanks