How can i complete my snail in the well in JavaScript challenge? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

How can i complete my snail in the well in JavaScript challenge?

11th Jan 2021, 10:32 PM
Motuncoded
Motuncoded - avatar
3 Answers
+ 2
function main() { var depth = parseInt(readLine(), 10); //your code goes here for(x = depth; x > 1; x = x +5){ if( x==1){ break; } console.log(x) } }
12th Jan 2021, 8:00 AM
Motuncoded
Motuncoded - avatar
0
Share the code you have so far. We will give you advice once we know what you are having trouble with specifically.
12th Jan 2021, 1:40 AM
Elizabeth Kelly
Elizabeth Kelly - avatar
- 1
First, x has to be declared as a variable... var x = or the code will not compile Second, what is x supposed to be? The number of days or the depth? It looks like you are trying to use it as both and that will never work. Third, you should reread the problem and look closely at the example provided. Your code needs to perform the same calcuations shown in the example. 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.
13th Jan 2021, 12:03 AM
Elizabeth Kelly
Elizabeth Kelly - avatar