Around 1:51 in the video, notice how she puts a <script> tag in there? The way it works is like this:
Create an html file (that's just a text file with a .html ending) somewhere on your computer. In the same folder that you put index.html, put a javascript file (that's just a textfile with a .js ending - let's call it game.js). Then, in your index.html file, put some html that includes the script tag with game.js, like Mary did in the video. index.html should look something like this:
<html>
<head>
<script src="game.js"></script>
</head>
</html>
Now, double click on that file in finder, and it should open it up in your browser. To open up the console to see the output of your javascript code, hit Command-alt-j (those three buttons at the same time).
Good luck on your journey, hope it's as fun for you as it has been for me so far :)
Answer from thataustin on Stack OverflowAround 1:51 in the video, notice how she puts a <script> tag in there? The way it works is like this:
Create an html file (that's just a text file with a .html ending) somewhere on your computer. In the same folder that you put index.html, put a javascript file (that's just a textfile with a .js ending - let's call it game.js). Then, in your index.html file, put some html that includes the script tag with game.js, like Mary did in the video. index.html should look something like this:
<html>
<head>
<script src="game.js"></script>
</head>
</html>
Now, double click on that file in finder, and it should open it up in your browser. To open up the console to see the output of your javascript code, hit Command-alt-j (those three buttons at the same time).
Good luck on your journey, hope it's as fun for you as it has been for me so far :)
If you're using Google Chrome you can use the Chrome Dev Editor: https://github.com/dart-lang/chromedeveditor
how do i execute my javascript code ?
Executing a JavaScript file directly from the browser - Stack Overflow
[deleted by user]
All javascript not working in chrome
OK, I had this issue and finally resolved it after several days. Clearing your cache and clearing your cookies do absolutely nothing. The problem is Reddit is using local storage https://www.w3schools.com/html/html5_webstorage.asp . For whatever reason there is something wrong with that. I closed Chrome and then went to ~/.config/google-chrome/Default/Local Storage and deleted everything with reddit in the file name. Your location will vary depending on OS.
More on reddit.comHow fast is the online JavaScript compiler?
What is a JavaScript compiler?
Does the JavaScript compiler work offline?
Videos
complete beginner here so please excuse the terminology and the lingo....
if i wanted to simply spit something out like
console.log('hello');
how do i essentially run that?
like in python, i know that i can just write something like
print('hello')
open the terminal change the cd and run it from there, but im not really familiar with the way that js is structured.
i looked at this here but it was not really making any sense to me unfortunately .
can someone provide some really simple clarity ?
This is not possible. The browser has no idea what context the JavaScript should run in; for example, what are the properties of window? If you assume it can come up with some random defaults, what about the behavior of document? If someone does document.body.innerHTML = "foo" what should happen?
JavaScript, unlike images or HTML pages, is dependent on a context in which it runs. That context could be a HTML page, or it could be a Node server environment, or it could even be Windows Scripting Host. But if you just navigate to a URL, the browser has no idea what context it should run the script in.
As a workaround, perhaps use about:blank as a host page. Then you can insert the script into the document, giving it the appropriate execution context, by pasting the following in your URL bar:
javascript:(function () { var el = document.createElement("script"); el.src = "PUT_URL_HERE"; document.body.appendChild(el); })();
Or you can use RunJS: https://github.com/Dharmoslap/RunJS
Then you will be able to run .js files just with drag&drop.
You don't need an extension for that. Use the console.
To open the Console tab, do one of the following:
Use the keyboard shortcut Command-Option-J (Mac) or Control-Shift-J (Windows/Linux).
Select View > Developer > JavaScript Console.
Now you can execute any Javascript you want. Variables and functions that are defined in the global scope of the current document can also be used.
For example, if the current site has jQuery included, you can send JSON to a remote script:
$.post( "http://example.com/test.php", { foo: "bar" } );
Accepted answer works, but here is another method if you dont have access to the javascript console.
The javascript protocol allows you to run javascript on any website just by entering it into the url bar in this format: javascript:alert('Hello World');