0
Still battling with snail in well javascript I don't know the problem it works fir some test cases but not others
This is what Ive done so far function main() { var depth = parseInt(readLine(), 10); //your code goes here var x = 7; var y = 2; var distance = 0; var day = 0; while(distance<depth){ day ++; distance +=x; distance -=y; if(distance+x>depth){ break; } else{ continue; distance= distance-y; } } console.log(day) }
2 Respostas
+ 4
Here is the improved code:
function main() {
var depth = parseInt(readLine(), 10);
//your code goes here
var x = 7;
var y = 2;
var distance = 0;
var day = 0;
while(distance<=depth){
distance +=x;
day ++;
if(distance>=depth){
break;
}
distance -= y
}
console.log(day)
}
To get the code functional in the while loop you need to change < to <= and in the if statement remove the +x and change the > to >=
Remove the else statement and just put distance - = y after the while statement
If this helps mark this as the best awnser
0
function main() {
var depth = parseInt(readLine(), 10);
//your code goes here
var x = 7;
var y = 2;
var distance = day = 0;
while(distance<depth){
day++;
distance += x;
if(distance>=depth) break;
distance -= y;
}
console.log(day);
}