I need help with Snail in The Well project
Problem: 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. I need help with this. I don't understand why I get just test case 2, 4 and 5. Can someone help me? If you help, thanks. My code: function main() { Ā Ā Ā var depth = parseInt(readLine(), 10); Ā Ā Ā //your code goes here Ā Ā Ā x = 0 Ā Ā Ā for(y = 0; x <= depth;x = x){ Ā Ā Ā Ā Ā Ā Ā x += 7; Ā Ā Ā Ā Ā Ā Ā if(x == depth){ Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā break Ā Ā Ā Ā Ā Ā Ā } Ā Ā Ā Ā Ā Ā Ā x -= 2 Ā Ā Ā Ā Ā Ā Ā if(x == depth){ Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā break; Ā Ā Ā Ā Ā Ā Ā } Ā Ā Ā Ā Ā Ā Ā y++ Ā Ā Ā } Ā Ā Ā console.log(y) }