- 2

Node js task, snail in the well

Please JavaScript developers how did you solve the snail question?? I mean the task in JavaScript.

17th May 2021, 2:44 PM
Abraham Samuel
Abraham Samuel - avatar
13 odpowiedzi
+ 3
Show your try first
17th May 2021, 3:01 PM
Ayush Kumar
Ayush Kumar - avatar
17th May 2021, 2:59 PM
Abraham Samuel
Abraham Samuel - avatar
0
Check JavaScript lesson
17th May 2021, 3:00 PM
Abraham Samuel
Abraham Samuel - avatar
0
I have but couldn't not get it
17th May 2021, 3:02 PM
Abraham Samuel
Abraham Samuel - avatar
0
function main() { var depth = parseInt(readLine(), 10); //your code goes here var snail = 0; var day = 1; function sum(you){ if(snail < you){ let snail=5; let day =+1; return sum(you) } else{ let snail =+2; console.log(day +1) } } sum(depth); }
17th May 2021, 3:06 PM
Abraham Samuel
Abraham Samuel - avatar
0
Must I change from if to while or for loop??
17th May 2021, 3:06 PM
Abraham Samuel
Abraham Samuel - avatar
0
Ok but yours is wrong
17th May 2021, 3:07 PM
Abraham Samuel
Abraham Samuel - avatar
0
Let me correct it function main() { var depth = parseInt(readLine(), 10); //your code goes here var days = 0, i = 0; while (true) { days++; i += 5; if (i >= depth) break; i += 2; } console.log(days); }
17th May 2021, 3:08 PM
Abraham Samuel
Abraham Samuel - avatar
0
Still wrong
17th May 2021, 3:14 PM
Abraham Samuel
Abraham Samuel - avatar
0
You didn't subtracted the 2 feet each day, On the last day you ought to add 2 cause it won't slip back
17th May 2021, 3:16 PM
Abraham Samuel
Abraham Samuel - avatar
0
Ok thanks for you help if not so wouldn't have gotten it thanks I just followed you. function main() { var depth = parseInt(readLine(), 10); var day=0; for(var len = 0; len < depth -2;){ len += 7 -2; day++; } len +=7; console.log(day) //your code goes here }
17th May 2021, 3:18 PM
Abraham Samuel
Abraham Samuel - avatar
0
Ok no probs
17th May 2021, 3:24 PM
Abraham Samuel
Abraham Samuel - avatar
0
Oh am sorry I didn't see the break
17th May 2021, 3:26 PM
Abraham Samuel
Abraham Samuel - avatar