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