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; } } }
14 Réponses
+ 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
+ 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
http://imgur.com/a/Jw1YvNK
Piyush[21 Dec❤️]
I can't attach the challenge, there's no button/option on it
+ 3
Signum
Oh, now I catch what you mean...
Sorry, I will try to fix it.
+ 2
✨The INDIAN✨ wow
Really thanks bro!
+ 2
Prince
for(;;)
{
console.log("test");
}
Thsi code doesn't have a statement and still works, unfortunately it is a infinite loop lol.
+ 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
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
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;
}
}
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);
}
- 2
Inbox