+ 1
Yo I'm doing javascript and Ive been battling with the snail in the well project and I need help
Pls why doesnt this work function main() { var depth = parseInt(readLine(), 10); //your code goes here var x = 7; var y = 2; var day = x-y; while(day<=depth){ console.log(day+x-y); if(day=depth){ break; } } }
7 ответов
+ 2
// For example your code could beginning as follows:
//your code goes here
var distance = 0;
var day = 0;
while(distance < depth){
day += 1;
distance += 7;
// … your further code
} // end while loop
console.log(day);
+ 4
First of all right will be:
if(day == depth);
or better
if(day === depth);
+ 3
Second - your logical way:
1) You get an input data for the variable depth.
2) For this you have to calculate how many days will it take the snail to get out of a well with the given depth.
That means you need to generate the days (1,2, …) in a loop, calculate the distance the snail covers each day, and break the loop when it reaches the desired distance.
+ 1
But then how do I count the number of days that the loop did
+ 1
I see thanks a lo
+ 1
A lot
0
The program is meant to calculate the amount of day it takes for a snail that climbs 7 feet ech day and slips back 2 feet each night to set out of a well with a random depth input