Why this code doesn't have a output? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

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; } } }

3rd Dec 2020, 2:57 PM
Willian
Willian - avatar
14 Answers
+ 8
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
4th Dec 2020, 4:46 AM
The INDIAN
The INDIAN - avatar
+ 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 👍
3rd Dec 2020, 3:23 PM
Piyush
Piyush - avatar
+ 3
http://imgur.com/a/Jw1YvNK Piyush[21 Dec❤️] I can't attach the challenge, there's no button/option on it
3rd Dec 2020, 4:02 PM
Willian
Willian - avatar
+ 3
Signum Oh, now I catch what you mean... Sorry, I will try to fix it.
3rd Dec 2020, 5:03 PM
Willian
Willian - avatar
+ 2
✨The INDIAN✨ wow Really thanks bro!
4th Dec 2020, 1:14 PM
Willian
Willian - avatar
+ 2
Prince for(;;) { console.log("test"); } Thsi code doesn't have a statement and still works, unfortunately it is a infinite loop lol.
4th Dec 2020, 2:15 PM
Willian
Willian - avatar
+ 1
Signum no I don't. I just placed him inside the for. And it can works without or with him.
3rd Dec 2020, 4:20 PM
Willian
Willian - avatar
+ 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"
3rd Dec 2020, 4:47 PM
Willian
Willian - avatar
+ 1
Signum it will be == if it is a "ask". For example: if(i==true) { document.write("True!"); } i=300 is a assignment.
3rd Dec 2020, 4:50 PM
Willian
Willian - avatar
+ 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
3rd Dec 2020, 4:57 PM
Willian
Willian - avatar
+ 1
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
4th Dec 2020, 1:53 PM
Willian
Willian - avatar
0
Yo realice de esta manera: function main(){ var depth = parseInt(readLine(), 10); // Your code goes here var distancia =0, dia = 0; for(var i =1; i >0; i++){ distancia = distancia +7; dia++; if(distancia >= depth){ console.log(dia); break; } distancia = distancia - 2; } }
13th May 2021, 1:40 AM
Alexis
Alexis - avatar
0
what is the problem in my code? sololearn says it is wrong var day = 0; var step = 0; while (day < 6) { day++; step = step + 7 - (2); if(day == 6){ step +=2; } console .log(step); }
13th May 2022, 2:51 PM
Miguel Alejandro Sislian Suez
Miguel Alejandro Sislian Suez - avatar
- 2
Inbox
5th Dec 2020, 12:03 PM
King