What's wrong with my code, snail practice? Please | Sololearn: Learn to code for FREE!

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();

4/13/2021 9:50:40 PM

Giio Crespo Solano

6 Answers

New Answer

+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); }

+2

Chandan Roy & Giio Crespo Solano, Also do..while works. https://code.sololearn.com/WowLH545Ohdw/?ref=app

+2

Boris Karandassov There are always several different ways to achieve a goal. 😊

+1

Oh, thank you CHANDAN ROY!!! 😊

0

https://www.sololearn.com/discuss/2746840/?ref=app

-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