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

15th May 2021, 2:57 PM
Adigwe Leo
Adigwe Leo - avatar
9 Respostas
0
please accept my congratulations! 🤩🥳👍
15th May 2021, 4:38 PM
Yaroslav Vernigora
Yaroslav Vernigora - avatar
+ 1
Thank you soo much you're awesome
15th May 2021, 4:34 PM
Adigwe Leo
Adigwe Leo - avatar
+ 1
Yeah
15th May 2021, 4:36 PM
Adigwe Leo
Adigwe Leo - avatar
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); }
15th May 2021, 3:23 PM
Yaroslav Vernigora
Yaroslav Vernigora - avatar
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
15th May 2021, 3:27 PM
Yaroslav Vernigora
Yaroslav Vernigora - avatar
0
Still not working
15th May 2021, 4:15 PM
Adigwe Leo
Adigwe Leo - avatar
0
My expected output is still wrong
15th May 2021, 4:16 PM
Adigwe Leo
Adigwe Leo - avatar
0
listen to my advice and redo your program
15th May 2021, 4:17 PM
Yaroslav Vernigora
Yaroslav Vernigora - avatar
0
You solved?
15th May 2021, 4:35 PM
Yaroslav Vernigora
Yaroslav Vernigora - avatar