29
Tried to make a simple button change color when clicked. It turned the whole page bright pink.
Following a tutorial, I wrote what I thought was a basic JavaScript event listener. The code was just supposed to target the button's ID and swap its background color. Instead, when I clicked it, the entire document body went fuschia. Took me 45 minutes to realize I'd typed 'document.body.style' instead of 'buttonElement.style'. It's a tiny typo, but it completely broke the logic. How do you guys catch these little syntax mistakes before you run the code? Is there a trick, or do you just have to get used to staring at it?
3 comments
Log in to join the discussion
Log In3 Comments
moore.oscar1mo ago
Honestly my friend did that and his whole site turned neon green.
8
alexh881mo ago
Check the CSS for a stray color code.
3
kai_west17d ago
My buddy had the exact same thing happen last month. He was trying to change a font size and typed document instead of the div name. Suddenly all the text on his page was microscopic. The trick is to read your selectors out loud, slowly. Say "document dot body dot style" and then look at what you actually wanted to change. It forces your brain to see the words, not just skim over them.
1