Why this code doesn't have a output? | SoloLearn: Learn to code for FREE!

+2

Why this code doesn't have a output?

I am making the challenge 3 of the javascript course. function main() { var depth = parseInt(readLine(), 10); //your code goes here var dia = 0; var current = 0; var usa = 0; for(i=1; i=300;) { usa = current + 7; dia++; if(usa == depth) { console.log(dia); i = 300; } else { usa = usa - 2; } } }

12/3/2020 2:57:49 PM

Willian

+5

function main() { var depth = parseInt(readLine(), 10); //your code goes here var i; var p=0; var sum=0; for(i=1;i>0;i++) { p=p+7; if(p>=depth) { console.log(i); break;} p=p-2; } } You must try this Since you don't have any step value in your loop It won't show any output or it will be an infinite loop 💐Happy coding

+12

W Try to attach the challenge itself! So that we can help you.. Also let us know about the test cases! Hope you understand 👍

+3

Signum Oh, now I catch what you mean... Sorry, I will try to fix it.

+3

✨The INDIAN✨ wow Really thanks bro!

+2

http://imgur.com/a/Jw1YvNK Piyush[21 Dec❤️] I can't attach the challenge, there's no button/option on it

+2

Prince the for doesn't need the 3 parameter to work. I already said this to another guy here, i can show you a code that does not have the 3 parameter and still works

+2

Prince for(;;) { console.log("test"); } Thsi code doesn't have a statement and still works, unfortunately it is a infinite loop lol.

+2

Okay i see Thanks

+1

Signum no I don't. I just placed him inside the for. And it can works without or with him.

+1

Signum the for doesn't need the i++ statement to work, i can do it without it. I placed the break in line 14 of the code (i=300; ) I am asking why the code does not have a output and shows the error "Execution timed out"

+1

Signum it will be == if it is a "ask". For example: if(i==true) { document.write("True!"); } i=300 is a assignment.

+1

Signum http://imgur.com/a/52yuP8p For doesn't need a break. This is not a infinite loop cuz somewhere the var usa will become = depth

+1

You probably forgot i++ as the third parameter of the for

+1

Okay show me

-2

Inbox