Hi I'm having a problem with Javascript, I'm currently learning js here and I'm stuck on the conditionals and loops code project | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Hi I'm having a problem with Javascript, I'm currently learning js here and I'm stuck on the conditionals and loops code project

Please anyone who has solved it and understands it should please help

3rd Apr 2022, 9:49 PM
Samuel Eric
Samuel Eric - avatar
15 Answers
+ 2
Your try?
3rd Apr 2022, 9:52 PM
Jayakrishna 🇮🇳
+ 1
Thats how i did it: function main() { var depth = parseInt(readLine(), 10); var climp = 0 var day = 0 var night = 0 for (; depth > climp;){ climp = climp + 7; day = day + 1 if(climp >= depth){ console.log(day) break; } else{ climp = climp -2; night = night +1; } } }
5th Apr 2022, 7:55 PM
yoelvi paniagua
yoelvi paniagua - avatar
0
do {snailProgress +=5} While{snailProgress <=depth}
3rd Apr 2022, 9:54 PM
Samuel Eric
Samuel Eric - avatar
0
Pls add full code link by saving it playground.. other wise I have to guess a lot...
3rd Apr 2022, 9:56 PM
Jayakrishna 🇮🇳
0
I know I'm wrong but what I don't know is what to do now
3rd Apr 2022, 9:56 PM
Samuel Eric
Samuel Eric - avatar
0
It climbs 7 steps and only falls 2 step back if not reached
3rd Apr 2022, 9:58 PM
Jayakrishna 🇮🇳
0
Yes it climbs 7ft a day and falls back 2ft in the night So total is 5ft in a day That's the snail's progress But I was asked for the days taken for the snail to leave the well of unknown depth
3rd Apr 2022, 10:00 PM
Samuel Eric
Samuel Eric - avatar
0
Can't send the playground link cos I don't see the option there but it's a code project in the Javascript conditionals and loops lesson It's at the end of the lesson
3rd Apr 2022, 10:02 PM
Samuel Eric
Samuel Eric - avatar
0
What if last, it reached in day by climbing 7fts..? You don't need to subtract 2 feets. If you subtract then it count as one more day.. Understood?
3rd Apr 2022, 10:04 PM
Jayakrishna 🇮🇳
0
Yeah I understand what you're saying so I won't base my day on the number of feet climbed So which parameter do I use?
3rd Apr 2022, 10:06 PM
Samuel Eric
Samuel Eric - avatar
0
No. It's based on feets only.. But add 7ft, only subtract 2 if not reached depth, day count+1. You can copy paste your code or share link saved copy-paste.. edit: Samuel Godswill Eric hope these helps... https://www.sololearn.com/discuss/2951346/?ref=app https://www.sololearn.com/discuss/2615972/?ref=app
3rd Apr 2022, 10:10 PM
Jayakrishna 🇮🇳
0
Thanks a lot
4th Apr 2022, 8:41 AM
Samuel Eric
Samuel Eric - avatar
0
No.. he doesn't have to
5th Apr 2022, 11:32 AM
Fayçal zemmouri
Fayçal zemmouri - avatar
0
I understand it now thanks
5th Apr 2022, 2:51 PM
Samuel Eric
Samuel Eric - avatar
- 2
You must learn Java first you can fine the basek there
5th Apr 2022, 11:14 AM
Mohmmed Elhadi
Mohmmed Elhadi - avatar