0

How can I do the second test of JS? That is about Condition's

I need some help, please

13th Jan 2022, 1:28 AM
Emmanuel Berroa
Emmanuel Berroa - avatar
3 Antworten
+ 1
The snail in the well? Hint: You can use a loop to calculate the distance the snail covers each day, and break the loop when it reaches the desired distance. The hint is pretty straightforward, make your attempt and share your code if you need help.
13th Jan 2022, 1:45 AM
CGM
CGM - avatar
0
var a = 0; var day = 1; do { day++ a = a + 7 - 2; } while (a<=dept); document.write(day-2);
13th Jan 2022, 2:00 AM
Emmanuel Berroa
Emmanuel Berroa - avatar
0
That will not work, since when the input is a multiple of 7, and perhaps at other times, you will reach the target value but the snail will return to the well during the night (-2), making you count one more day... You have to use that -2 only "if" necessary. (and I think you should use console.log instead of document.write)
13th Jan 2022, 2:30 AM
CGM
CGM - avatar