0
Can you correct my solution to this JS problem?
9 odpowiedzi
+ 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
+ 2
Rik Wittkopp to test the code in code playground, you must replace 'readline' by 'prompt', and call 'main()' function ;)
+ 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.
+ 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)
+ 1
so, if that's the logic wich is bad, you should try to implement algorithm with a loop, and no division...
+ 1
Thanks visph
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.
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) ;)
0
Once again: rounding is not the case here.