0

Snail in the wall (js)

I'm completely beginner in js and I'm trying to solve thos code chalange: The chalange is basically about a snail climbing 7 feet up the wall each day and 2 feet down each night. And I should output the number of days it takes for snail to climb out of the wall completely. I wrote this code but I don't know what's is the problem with it and why it doesn't work. function main() { var depth = parseInt(readLine(), 10); //your code goes here var day = 0; do depth -= 7 while (depth >= 0){ depth += 2 day++ } console.log(day) } I would appreciate if I could get some help about this.

28th Aug 2022, 11:08 AM
pedram ch
pedram ch - avatar
8 Respostas
+ 3
The do part is wrong. Review that first.
29th Aug 2022, 8:04 AM
Ausgrindtube
Ausgrindtube - avatar
+ 2
Can you share your updated code?
29th Aug 2022, 4:59 PM
Ausgrindtube
Ausgrindtube - avatar
+ 2
Ok, I don't see the semi-colon... Check the logic. What does your while condition say? You have a while code statement but your do statement executes until your while condition is met (if you removed the curly brackets).
29th Aug 2022, 6:00 PM
Ausgrindtube
Ausgrindtube - avatar
+ 2
Great work! And no worries about the help. That's what the community is here for.
30th Aug 2022, 6:17 AM
Ausgrindtube
Ausgrindtube - avatar
+ 1
Ausgrindtube oh I got it now. Sorry I forgot to add semi colon to my previous message. Thank you so much for the help
29th Aug 2022, 10:03 PM
pedram ch
pedram ch - avatar
+ 1
Ausgrindtube ❤️❤️🙏
3rd Sep 2022, 5:26 PM
pedram ch
pedram ch - avatar
0
Ausgrindtube thank you for your respons I read js course about do while again and checked some examples provided by other people. I undrestood I missed a semicolon after do code block but after adding it, it still doesn't work
29th Aug 2022, 4:56 PM
pedram ch
pedram ch - avatar
0
Ausgrindtube I just changed the do block do{ depth -= 7 }
29th Aug 2022, 5:11 PM
pedram ch
pedram ch - avatar