0

Snail in the well javascript

Hello, can someone help me evaluate my code for this js question, i keep getting just the first case wrong function main() { var depth = parseInt(readLine(), 10); //your code goes here var day=0; var climb=7; var slip=2; for(dis=0;dis<=depth;){ dis=dis+climb; if(dis<=depth){ dis=dis-slip; day++; } else{ day++; break; } } console.log(day); }

24th Feb 2022, 8:46 AM
shubham damania
shubham damania - avatar
3 Respuestas
+ 1
When the snail climbs in the first day should be one not zero, imagine you got a new job, will the first day of the job start from zero (first day: means day one)?
24th Feb 2022, 9:34 AM
Mohammed
0
If i set the day as one then the all the cases go wrong... Secondly the distance covered at day 0 is 0 day 1 is 5 day 2 is 10 and so on.
24th Feb 2022, 2:44 PM
shubham damania
shubham damania - avatar
0
For me this worked: function main() { var depth = parseInt(readLine(), 10); //your code goes here var dayssum=1 for (x=7; x<depth; x+=7) { if(x>=depth) break; else x-=2 dayssum++} console.log(dayssum) }
6th Jun 2022, 12:57 PM
Anush Avetisyan