- 2
Node js task, snail in the well
Please JavaScript developers how did you solve the snail question?? I mean the task in JavaScript.
13 ответов
+ 3
Show your try first
0
Check JavaScript lesson
0
I have but couldn't not get it
0
function main() {
var depth = parseInt(readLine(), 10);
//your code goes here
var snail = 0;
var day = 1;
function sum(you){
if(snail < you){
let snail=5;
let day =+1;
return sum(you)
}
else{
let snail =+2;
console.log(day +1)
}
}
sum(depth);
}
0
Must I change from if to while or for loop??
0
Ok but yours is wrong
0
Let me correct it
function main() {
var depth = parseInt(readLine(), 10);
//your code goes here
var days = 0, i = 0;
while (true) {
days++;
i += 5;
if (i >= depth) break;
i += 2;
}
console.log(days);
}
0
Still wrong
0
You didn't subtracted the 2 feet each day,
On the last day you ought to add 2 cause it won't slip back
0
Ok thanks for you help if not so wouldn't have gotten it thanks I just followed you.
function main() {
var depth = parseInt(readLine(), 10);
var day=0;
for(var len = 0; len < depth -2;){
len += 7 -2;
day++;
}
len +=7;
console.log(day)
//your code goes here
}
0
Ok no probs
0
Oh am sorry I didn't see the break