- 1
How to write Loop?
The snail climbs up 7 feet each day and slips back 2 feet each night. How many days will it take the snail to get out of a well with the given depth? Sample Input: 31 Sample Output: 6 Explanation: Let's break down the distance the snail covers each day: Day 1: 7-2=5 Day 2: 5+7-2=10 Day 3: 10+7-2=15 Day 4: 15+7-2=20 Day 5: 20+7-2=25 Day 6: 25+7=32 So, on Day 6 the snail will reach 32 feet and get out of the well at day, without slipping back that night.
3 Respostas
+ 2
for(let a = 0; a < 5; a++){
//code here
}
Lisa i literally forgot about that, thanks for correcting me.
idk why people upvoted my answer. due to that I assumed it was right...
0
Not cheap
0
If you use plain javascript, wouldn't it be let a = 0/ var a = 0? Rellot's screwdriver ?
วุฒิชัย คำนนท์ What do you mean by "not cheap"? "Expensive loop"?
If you need help with the code, please link it. Hint: You can use a while loop and once the snail is out of the well, it doesn't slip down at night anymore.