Why my code for 'The snail in the well' project in JavaScript course is wrong? | Sololearn: Learn to code for FREE!

+1

Why my code for 'The snail in the well' project in JavaScript course is wrong?

function main() { var depth = parseInt(readLine(), 10); //your code goes here var days = 0; var feet = 0; while(feet < depth){ feet = feet+7-2; days++; } document.write(days); }

8/7/2022 1:57:55 PM

Doodle Ghost

3 Answers

New Answer

+3

oh. It's js code so use console.log(days) ; Instead of document.write(days);

+1

Hint: if it reached on climbing 7 feet depth then it won't fall back 2 feet.

0

It still didn't work? I put if statement,if after add 7 and feet it still lower than depth it will minus 2. Is it because my code have error in it? function main() { var depth = parseInt(readLine(), 10); //your code goes here var days = 0; var feet = 0; while(feet < depth){ feet = feet + 7; if(feet < depth){ feet = feet - 2; } days++; } document.write(days); }