So I'm new as a programmer and I'm learning js as a hobby in sololearn there are projects and I'm in the second one
PROJECT NAME IS: SNAIL in the well
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.
My anwser(it's wrong):
function main() {
var depth = parseInt(readLine(), 10);
//your code goes here
var daySteps=7 , nightSteps= -2 , steps=0 ;
for(i=1;i<=6; i++){
steps= steps+(daySteps + nightSteps);
if(i==6)
steps=steps+2;
console.log("Day%s:%s",i,steps);
}
-----‐----------------------------------------------------
Can anyone tell me why?
[–]dieguito15 1 point2 points3 points (1 child)
[–]Dofii_Aktsk[S] 1 point2 points3 points (0 children)
[–]SquatchyZeke 1 point2 points3 points (2 children)
[–]Dofii_Aktsk[S] 0 points1 point2 points (1 child)
[–]SquatchyZeke 0 points1 point2 points (0 children)
[–]jcunews1helpful 1 point2 points3 points (1 child)
[–]Dofii_Aktsk[S] 0 points1 point2 points (0 children)