+ 3

Snail Project Javascript

I have a problem with the third case of the project solving. function main() { var depth = parseInt(readLine(), 10); //tu código va aquí var i = 0; var up = 7; var down = 2; var result = 0; while (i>=0){ result = result + up - down; i++; if ((result+up) >= depth){ i++; console.log(i); break; } } }

4th Jan 2021, 2:03 AM
the mu n ix
the mu n ix - avatar
3 Antworten
+ 4
Your error was the sequence you did your math. You add up to result, then increment I, then check whether it is bigger than depth and then finally remove down Here is the fixed code: function main() { var depth = parseInt(readLine(), 10); //tu código va aquí var i = 0; var up = 7; var down = 2; var result = 0; while (result<=depth){ result += up; i++; if (result>= depth){ console.log(i); break; } result-=down; } } Hope this helps 👍
4th Jan 2021, 3:27 AM
Pieter Edwards
Pieter Edwards - avatar
+ 1
I get in all of the cases a correct answer, but in the third one Its incorrect.
4th Jan 2021, 2:15 AM
the mu n ix
the mu n ix - avatar
0
function main(){ var depth = parseInt(readline(),10); //your code goes here var height = 0; var day = 0; while(height < depth){ day += 1; height += 7; if (height >= depth){ break; } else{ height -= 2; } } return console.log(day); } This is my code and it's correct :)
27th Jul 2021, 6:49 AM
Mohamad Zamin Sayan
Mohamad Zamin Sayan - avatar