+ 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; } } }
3 Answers
+ 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 👍
+ 1
I get in all of the cases a correct answer, but in the third one Its incorrect.
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
:)