3rd Mar 2021, 7:43 AM
Sergii Poberezhniuk
Sergii Poberezhniuk - avatar
9 Respuestas
+ 2
Sergii Poberezhniuk You will need to use a while loop to ascertain your daily height. When I was trying to test, I noted console.log was failing to generate an output when using the Pre- formatted code I have also tested other codes with the same result, so it makes it a bit hard to verify. Hoping just a Sololearn glitch
3rd Mar 2021, 8:43 AM
Rik Wittkopp
Rik Wittkopp - avatar
+ 2
Rik Wittkopp to test the code in code playground, you must replace 'readline' by 'prompt', and call 'main()' function ;)
3rd Mar 2021, 8:46 AM
visph
visph - avatar
+ 2
There are many ways to get your answer. but if you're trying to get an answer without having to use % or rounding the number, remember that the snail slips by 2 feet the night before the next day. you can use a while loop. Increase the value of x by 5 i.e (7-2) every instance (so that x<depth and at the same time x is the immediate previous multiple of 5 before depth) if the depth == x && is a factor of 5, x/5 is the answer if (depth-x)==2 then the snail climbed out of the well on the last day, (x/5)+1 is the answer. if (depth-x)<2 the the snail slipped back by that night, (x/5) is the answer if depth<7 as you stated, answer will be 1.
4th Mar 2021, 1:07 AM
Tope Akinkuade
Tope Akinkuade - avatar
+ 1
to convert decimal to integer, you need to know how handle rounding: you could use Math.round, Math.floor, Math.ceil, or even Math.trunc... as well as shorthand ways (wich return 32 bits signed int, truncating the value, as value binary OR zero)
3rd Mar 2021, 8:10 AM
visph
visph - avatar
+ 1
so, if that's the logic wich is bad, you should try to implement algorithm with a loop, and no division...
3rd Mar 2021, 8:40 AM
visph
visph - avatar
+ 1
Thanks visph
3rd Mar 2021, 8:47 AM
Rik Wittkopp
Rik Wittkopp - avatar
0
Thx though I guess the case is not about rounding but probably there must be a mistake in my code or smth is missing in it.
3rd Mar 2021, 8:22 AM
Sergii Poberezhniuk
Sergii Poberezhniuk - avatar
0
I don't know if your logic is valid, nor wich one of rounding function should be used (probably floor/trunc, surely not ceil)... but it pass at least the example test case if you convert result to int (for input 31, trunc(6.2)==6) ;)
3rd Mar 2021, 8:26 AM
visph
visph - avatar
0
Once again: rounding is not the case here.
3rd Mar 2021, 8:38 AM
Sergii Poberezhniuk
Sergii Poberezhniuk - avatar