I am a beginner, all I have done is practiced writing code in Codecademy. After extensive searches of google for how to run a .js file, I turned up nothing. I assume I am asking the wrong question, and I am sure it is simple, but I couldn't find anything.
To execute JavaScript in a browser you have two options — either put it inside a script element anywhere inside an HTML document, or put it inside an external JavaScript file (with a . js extension) and then reference that file inside the HTML document using an empty script element with a src attribute.
To write a JavaScript, you need a web browser and either a text editor or an HTML editor. Once you have the software in place, you can begin writing JavaScript code. To add JavaScript code to an HTML file, create or open an HTML file with your text/HTML editor.
To enter JavaScript statements and expressions interactively in the Console: Right-click in a webpage and then select Inspect. DevTools opens. Or, press Ctrl + Shift + J (Windows, Linux) or Command + Option + J (macOS), to directly open the DevTools console.
Write basic HTML there like below
<html>
<head>
</head>
<body>
Hello World!
</body>
</html>
Add a script tag and write your js inside it like below
<html>
<head>
<script>
alert("hello");
</script>
</head>
<body>
Hello World!
</body>
</html>
or you can write your js code in a file and save as .js file and link that in the above code
<html>
<head>
<script src="myScript.js"></script>
</head>
<body>
Hello World!
</body>
</html>
Save this as yourfile.HTML and open in any browser
Here's a link to learn more: http://www.w3schools.com/js/js_whereto.asp.
This is an addition to previous answers.
If you want to practice simple JavaScript instructions and code snippets like you did in Codecademy you can use:
First install and setup Nodejs in your machine. Then write your javascript and save it in a folder. Open the command prompt inside the folder and write the command to execute.
node a.js
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With