Yo I'm doing javascript and Ive been battling with the snail in the well project and I need help | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 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; } } }

31st Jul 2021, 6:02 AM
David
David - avatar
7 Answers
+ 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);
31st Jul 2021, 9:32 AM
JaScript
JaScript - avatar
+ 4
First of all right will be: if(day == depth); or better if(day === depth);
31st Jul 2021, 6:14 AM
JaScript
JaScript - avatar
+ 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.
31st Jul 2021, 7:46 AM
JaScript
JaScript - avatar
+ 1
But then how do I count the number of days that the loop did
31st Jul 2021, 8:59 AM
David
David - avatar
+ 1
I see thanks a lo
31st Jul 2021, 9:50 AM
David
David - avatar
+ 1
A lot
31st Jul 2021, 9:50 AM
David
David - avatar
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
31st Jul 2021, 7:29 AM
David
David - avatar