+ 1

Code 23 snail in well

I’m having a very hard time with this one. Please help. //your code goes here var feet=0 var day=0 do{ feet+7; day++; }while (feet < depth){ feet-2; }console.log(day); } What is wrong with this code?

15th Apr 2022, 10:58 PM
Heather
Heather - avatar
4 Answers
+ 3
First of all you do not have function main expression here. Also you should take depth as an input and then use it to calculate days required. Depth is undefined variable in your code. In addition feet+7 or - will not increase or decrease feet variable. Use += and -= instead. I would have solved it with something like that: function main() { var depth = parseInt(readLine(), 10); //your code goes her var days = 0; while (depth > 0){ days += 1; depth -= 7; if (depth <= 0) break; depth+= 2; } console.log(days) }
15th Apr 2022, 11:14 PM
Aleksei Radchenkov
Aleksei Radchenkov - avatar
+ 1
I used a slightly different approach and it worked...I'm a beginner too by the way function main() { var depth = parseInt(readLine(), 10); //your code goes here var feet=0; var day=0; for(;feet<=depth;){ feet+=7; day++; if(feet>=depth){ break; } else { feet-=2; } } console.log(day); }
28th Apr 2022, 1:47 PM
Perisia Kagize
Perisia Kagize - avatar
+ 1
Perisia, This is what I went with. It took me about (don’t laugh) 2 hours. But with some persistence I finally managed. Thanks for the advice though. Good to know there is a good community here that is willing to help.
30th Apr 2022, 11:56 AM
Heather
Heather - avatar
+ 1
😆(literally didn't laugh), actually I too tried a couple of times.....thank you for a heart warming reply, it made my day.
30th Apr 2022, 12:51 PM
Perisia Kagize
Perisia Kagize - avatar