Skip to content
Advertisement

How to change elements color with a click

I know this is basic. You’ll have to excuse me. I’m a js student and I’m having such a hard time with an issue here. So… I have this code: As you can see, the button is creating squares. Now – the issue that I’m having is that it is suppose to change the respective […]

Why can’t i output outside a function, in this scenario where i’m creating a simple counter i’m confused as to why it’s working inside and not out?

Why can’t I output outside the function here, why does it need to be inside? Answer Because if it were where you’ve shown in the question, the value would be 0. The code runs immediately on page load, it doesn’t wait for something to call countJar. Where it is now, it doesn’t run until countJar is called. If you mean

Advertisement