Huh? How did this happen?

I got this to pop up on my screen
image
Here is how! But first, let me explain how I came across it!

I am pretty bad at JavaScript. I was messing with some code, and the code was broken/wrong. It was so wrong in fact, that it gave me that (the guy up there). here is my JavaScript and HTML code. I don’t think the CSS matters as I didn’t mess with it.

First the JavaScript:

var text = document.getElementById("type");
var i = 0

while (true) {
  setTimeout(function() {
    text.innerHTML = i;
  }, 100);
  i++
}

Then we have the CSS. Sure there is the start and stuff, but this is just what I have:

<p id="type">
      This will be jumbled up and then it will type it out. 
    </p>

So when I was coping that HTML into this post, I accidentally changed one of the words, and of course that re-loaded the tab, and then the little guy is gone.

Does anyone know what this is?

1 Like

Yes, it means basically your computer can’t handle your code (tab crashed). It’s not a problem with Glitch. Don’t run while true loops, they’re dangerous

1 Like

everything in the while loop is run repeatedly until the condition isn’t met. in this case, since the condition is ‘true’ it runs forever.
you may be thinking it will wait 100 before the while goes thru again, but no. it just does it as fast as it can repeatedly forever.

you may be looking for:

let text = document.getElementById("type");
let i = 0
setInterval(function(){
text.innerHTML = i
i++
},100)
1 Like

yep! Thanks!

1 Like

For future reference, having a more descriptive title helps other users since they don’t need to open the post to know if it’s relevant to them.

You can name it for example “browser crashed and I don’t know why” or more specifically “my JavaScript code seems to crash the browser”
(I would avoid the word “help” because it’s quite obvious that you need someone’s help if you’re not posting on the gallery or feature ideas)

3 Likes