0
How do I fix my snail in the well code
function main() { var depth = parseInt(readLine(), 10); //your code goes here var Distance_up = 7; var DistanceDown = 2; var distance_covered = Distance_up - DistanceDown; position = 0; days = 0; while (position < depth){ DailyDepth = depth ; days++ ; position += Distance_up ; position -= DistanceDown; if (position >DailyDepth) { position -= Distance_up position -= DistanceDown; break ; } } console.log(days); } My expected output is 9 instead of 8
9 Réponses
0
please accept my congratulations! 🤩🥳👍
+ 1
Thank you soo much you're awesome
+ 1
Yeah
0
function main() {
var depth = parseInt(readLine(), 10);
//your code goes here
var Distance_up = 7;
var DistanceDown = 2;
//var distance_covered = Distance_up - DistanceDown;
position = 0;
days = 0;
while (position <= depth){
//DailyDepth = depth ;
days++ ;
position += Distance_up ;
position -= DistanceDown;
if (position > depth) {
//position -= Distance_up
// position -= DistanceDown;
break ;
}
}
console.log(days);
}
0
I removed the extra lines from your code, keeping the same functionality. you should not add 7 feet and immediately subtract two. add 7 feet, add a new day, then do a distance check. if it is greater than or equal to the height of the well, you are out. if not, subtract 2 feet and return to the beginning
0
Still not working
0
My expected output is still wrong
0
listen to my advice and redo your program
0
You solved?