+ 2

Please who can explain to me how the snail in the well question works it is in JavaScript under loops

Code coach question

15th Sep 2021, 2:32 PM
Shittu - Abraham Enoch
Shittu - Abraham Enoch - avatar
3 ответов
+ 2
Yes, the idea is to put your code into a loop. While snale is not at the top add seven and take two
15th Sep 2021, 3:23 PM
Brain & Bones
Brain & Bones - avatar
+ 1
Run a while loop . Inside loop increment snake position by 7 and increment day as well by 1. Now check if snake position is less than equal to given distance . If yes then break the loop , else decrement snail position by 2.
16th Sep 2021, 9:45 AM
Abhay
Abhay - avatar
+ 1
Very Simple Take a look: function main() { var depth = parseInt(readLine(), 10); //your code goes here var day=0; var i; for( i=0; day < depth; i++) { day += 7; if(day >= depth) { i += 1; break; } day -= 2; } console.log(i); }
8th Oct 2021, 8:54 PM
Ben
Ben - avatar