Question about JavaScript in testing vs in use in text editor

Why are JS’s statements different from testing i.e. challenges on freecodecamp where its not used with html and css vs in text editor used with html and css? I noticed that when trying it out on jsfiddle, invoking for example isnt the same, there’s always when you have to use document.getElementById in many examples, same for other things too.

I’m sorry, but I don’t understand what you’re asking.

What im asking is why is using JavaScript different from practicing in lets says webtoolkitonline where no html and css is involved with it vs being used with for example where html and css are involved. I noticed invocations dont work the same way for example, there’s always that some additional variable needed to be added in text editor when used with HTML and CSS.

If I understand what you’re talking about, then the difference is that there are some tools that allow you to execute JavaScript functions directly. These are for testing your JavaScript directly and in isolation. Other tools like jsfiddle are for testing websites. In a website, you need a mechanism to actually call JavaScript functions.

1 Like

Oh ok, can you give me some sources for those mechanism if available? I would like to practice it, im using w3schools and developer mozzila from time to time, but i wish to get better and better.

Usually JS functions are going to be called via an event like a button click. It depends on what you are trying to make the website respond to.