+ 2
Please who can explain to me how the snail in the well question works it is in JavaScript under loops
Code coach question
3 ответов
+ 2
Yes, the idea is to put your code into a loop. While snale is not at the top add seven and take two
+ 1
Run a while loop . Inside loop increment snake position by 7 and increment day as well by 1.
Now check if snake position is less than equal to given distance . If yes then break the loop , else decrement snail position by 2.
+ 1
Very Simple
Take a look:
function main() {
var depth = parseInt(readLine(), 10);
//your code goes here
var day=0;
var i;
for( i=0; day < depth; i++)
{
day += 7;
if(day >= depth)
{
i += 1;
break;
}
day -= 2;
}
console.log(i);
}