What's wrong with my code, snail practice? Please | Sololearn: Learn to code for FREE!
Neuer Kurs! Jeder Programmierer sollte generative KI lernen!
Kostenlose Lektion ausprobieren
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 Antworten
+ 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