Node js task, snail in the well | SoloLearn: Learn to code for FREE!

-2

Node js task, snail in the well

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

5/17/2021 2:44:01 PM

Abraham Samuel

16 Answers

New Answer

+3

Show your try first

+2

Abraham Samuel Where can I find task description ?

+1

Abraham Samuel My answer is already approved.

0

https://www.sololearn.com/Course/JavaScript/?ref=app

0

Check JavaScript lesson

0

I have but couldn't not get it

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); }

0

Must I change from if to while or for loop??

0

Ok but yours is wrong

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); }

0

Abraham Samuel Double-check my answer and statements of question. function main() { var depth = parseInt(readLine(), 10); //your code goes here var days = 0, i = 0; while (true) { days++; i += 7; if (i >= depth) break; i -= 2; } console.log(days); } /*The snail climbs up 7 feet each day and slips back 2 feet each night. */

0

Still wrong

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

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 }

0

Ok no probs

0

Oh am sorry I didn't see the break