+ 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?
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)
}
+ 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);
}
+ 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.
+ 1
đ(literally didn't laugh), actually I too tried a couple of times.....thank you for a heart warming reply, it made my day.