0
Snail in the well javascript
Hello, can someone help me evaluate my code for this js question, i keep getting just the first case wrong function main() { var depth = parseInt(readLine(), 10); //your code goes here var day=0; var climb=7; var slip=2; for(dis=0;dis<=depth;){ dis=dis+climb; if(dis<=depth){ dis=dis-slip; day++; } else{ day++; break; } } console.log(day); }
3 Réponses
+ 1
When the snail climbs in the first day should be one not zero, imagine you got a new job, will the first day of the job start from zero (first day: means day one)?
0
If i set the day as one then the all the cases go wrong...
Secondly the distance covered at day 0 is 0 day 1 is 5 day 2 is 10 and so on.
0
For me this worked:
function main() {
var depth = parseInt(readLine(), 10);
//your code goes here
var dayssum=1
for (x=7; x<depth; x+=7) {
if(x>=depth) break;
else x-=2
dayssum++}
console.log(dayssum)
}