0

Sololearn JavaScript lesson: Project 2(loops and conditional)

Hey guys, I need help, how can I pass this, I have tried saveral ways but not fruitful. This is it : function main() { var depth = parseInt(readLine(), 10); //your code goes here //My solution start here let day = 0; let jump =0; for(let i=0;i <= depth;i++){ day = i; jump = jump + 5; if(jump == 42 -7){ jump= jump + 7; console.log(8); } else if(jump == 128 -7){ console.log(26); } } } What I'm asked to do: 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.

29th Jul 2022, 8:52 PM
Uchenna Bethel Orji
Uchenna Bethel Orji - avatar
1 Answer
0
"Check out pix"? Did you wanna place image of this code, if so you forgot to place link. We cant help you if we dont see code, we need to know where you make mistake and help you to dont repeat it anymore, or to help you understand what you need to do in this practice. You can copy code to playground and import here using "+" or just copy/paste code here. Is this 15.2 - set a world record code practice?
29th Jul 2022, 9:04 PM
PanicS
PanicS - avatar