+ 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));
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));
+ 3
Alim Niyazov
First thing you can't change main function otherwise readLine() will be undefined
2nd thing loop is going till infinity..
+ 2
i -= 2
Shouldn't there be a semicolon at the end of this statement ?
+ 2
Arsenic Semicolon doesn't matter in JS
+ 1
Thank you very much, I spent a lot of time on this task