+ 1

what is wrong in my code?

function climb() { var height = parseInt(readLine(), 10); let days = 0; if (height<= 0) return days; for (let i = 0; ; i -= 2) { // i -= 2 i += 7; ++days; if (i >= height) break; i -= 2 } return days; } console.log(climb(days));

15th Dec 2020, 3:13 PM
Alim Niyazov
Alim Niyazov - avatar
5 Respostas
+ 3
Alim Niyazov Here is some changes in your code and it is working fine. //what is wrong in my code? //what is wrong in my code? function main() { var height = parseInt(readLine(), 10); let days = 0; for (let i = 0; ; i -= 2) { // i -= 2 i += 7; days++ if (i >= height) { break; } } console.log(days) } //console.log(climb(days));
15th Dec 2020, 4:06 PM
A͢J
A͢J - avatar
+ 3
Alim Niyazov First thing you can't change main function otherwise readLine() will be undefined 2nd thing loop is going till infinity..
15th Dec 2020, 4:03 PM
A͢J
A͢J - avatar
+ 2
i -= 2 Shouldn't there be a semicolon at the end of this statement ?
15th Dec 2020, 3:23 PM
Arsenic
Arsenic - avatar
+ 2
Arsenic Semicolon doesn't matter in JS
15th Dec 2020, 4:08 PM
A͢J
A͢J - avatar
+ 1
Thank you very much, I spent a lot of time on this task
15th Dec 2020, 4:11 PM
Alim Niyazov
Alim Niyazov - avatar