0
How can i complete my snail in the well in JavaScript challenge?
3 Réponses
+ 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)
}
}
0
Share the code you have so far. We will give you advice once we know what you are having trouble with specifically.
- 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.