Why my Browser Crash in 7/13


#1
for (var i = 10; i <= 0; i--) {
console.log(i);
}

this is my code! but my browser crash!!
Can someone help me?


#2

I believe that the problem is in the second part of the "For" Loop, because instead of
i >= 0;
you did i <= 0; .
Unusually, when I do it to my computer, I do not see any crashing. Why, I do not know.
The only problem I can see, though, is that you have to change your < to >.

Hope it helped!


#4

I'd agree with this. As i is 10 and therefore i is bigger than 0 this condition would be false i <= 0; and the loop would not even execute once but not crash your browser.


#5

I also noticed that the incremental portion (third part of your loop)is reading as i-- but I used i-=1 (so it can decrement down by 1). This is how my code looked (notice as well, that the second part of the code has i>= 0).

for (var i = 10; i >= 0; i-=1) {
	console.log(i);
}

I hope this helped! Did you get it to work?


#6

i-=1 and i-- both decrement by 1. i-- is faster to write but i-=x is more versatile as it must not only be 1. In the ends its your choice what you pick but it shouldn't make a difference.