0

What's wrong with my code, snail practice? Please

function main() { var depth = parseInt(readLine(), 10); //tu código va aquí var day=0; var avan=0; while(avan<depth){ avan+=7; if(avan>=depth ){ day++; console.log(day) break; }else{ avan=avan-2 day++; } } } main();

13th Apr 2021, 9:50 PM
Giio Crespo Solano
Giio Crespo Solano - avatar
6 Réponses
+ 3
Giio Crespo Solano some problems with the way you have written your logic. corrected your code a bit. 1.The snail climbs up 7 feet each day and slips back 2 feet each night. (This happens in 1 day.) 2. your if block doesn't make sense. function main() { var depth = parseInt(readLine(), 10); //your code goes here var avan =0; var day = 0; while (avan < depth){ avan +=7; day +=1; if (avan >=depth){ break; } else{ avan-=2; } } console.log(day); }
13th Apr 2021, 10:16 PM
CHANDAN ROY
CHANDAN ROY - avatar
+ 2
Chandan Roy & Giio Crespo Solano, Also do..while works. https://code.sololearn.com/WowLH545Ohdw/?ref=app
15th Apr 2021, 6:37 PM
ボリス
+ 2
Boris Karandassov There are always several different ways to achieve a goal. 😊
16th Apr 2021, 1:49 AM
CHANDAN ROY
CHANDAN ROY - avatar
+ 1
Oh, thank you CHANDAN ROY!!! 😊
14th Apr 2021, 2:30 PM
Giio Crespo Solano
Giio Crespo Solano - avatar
14th Apr 2021, 3:45 AM
Arun Ruban SJ
Arun Ruban SJ - avatar
- 2
you can pass it using one line console.log(Math.round(depth/(7-2))); or console.log(Math.round(depth/5)); round method will try to make the float as int without decimals . no doubt u know it what it does i cant explain it easily but put a decimals floats as param of this method and see whts gonna happen
15th Apr 2021, 9:44 PM
Imrane Aabbou
Imrane Aabbou - avatar