+ 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); }

7th Aug 2022, 1:57 PM
Doodle Ghost
3 odpowiedzi
+ 3
oh. It's js code so use console.log(days) ; Instead of document.write(days);
7th Aug 2022, 3:09 PM
Jayakrishna 🇮🇳
+ 1
Hint: if it reached on climbing 7 feet depth then it won't fall back 2 feet.
7th Aug 2022, 2:03 PM
Jayakrishna 🇮🇳
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); }
7th Aug 2022, 3:00 PM
Doodle Ghost