0

Can anyone help me Javascript challenge I have been solving J's and CSS challenges since. The "Snail in the well" Please

Javascript

29th Dec 2020, 2:39 PM
INERTIA
INERTIA - avatar
6 Respostas
+ 2
Odelola Oluwaseyi .M. Post your attempt first to get help from the community These Challenges and projects are made to test the users understanding and knowledge .So try doing it yourself for your own progress . If you want help with the codes , Show your attempt first .
29th Dec 2020, 2:41 PM
Alphin K Sajan
Alphin K Sajan - avatar
0
function main() { var depth = parseInt(readLine(), 10); //your code goes here var snailclimb = 7; var snailslip = 2; var dailysum=0; var day = 0; var i = 0; do{ dailysum += snailclimb; day++; dailysum -= snailslip; console.log(day); }while(dailysum>depth); }
29th Dec 2020, 3:41 PM
INERTIA
INERTIA - avatar
0
in 'while' condition you should use 'daily < depth). Otherwise your loop will always iterate only once, since 'dailysum' equals to 0.
29th Dec 2020, 8:35 PM
Artur
Artur - avatar
0
And don't console.log 'day' on every iteration. Instead, console.log it if the problem condition solution is met.
29th Dec 2020, 8:39 PM
Artur
Artur - avatar
0
@Artur thank you so much like you are the console. As if you knew that the iteration is going only once. God bless you thank you for the feedback.
29th Dec 2020, 8:58 PM
INERTIA
INERTIA - avatar
0
You should also add: If(dailysum>=depth) break; Before the dailysum-=snailslip;
29th Dec 2020, 8:59 PM
Ri He
Ri He - avatar