To begin, you can open a valid HTML file with your browser. There are a few ways to do this, and the easiest way is to right click the file and use “Open With” to open the file with a web browser. For more information, visit https://www.codecademy.com/articles/local-web-page
Let’s open our editor and create a basic webpage using the following code:
</script>. There is a function
console.log that allows us to output values to the console. Let’s use it in our first script. Let’s insert a set of script tags inside our previous HTML code with
To do this, we can use an attribute within the script tag which looks like:
console.log('I am an external script'). So our example.js file should look like:
As long as we entered everything correctly and the files are in the same folder, opening the HTML file with a web browser should look like:
You can see both of the console.log statements printed their values into the console. It’s important to note, however, that if the file was in a different location or named incorrectly, our browser would try to load the file but would return an error instead. This would look like:
And our console.log would never show, of course.
That’s all there is to it! I also added a special file to this page, and it is logging a question for you in the console. Please take a look and answer the question in the comments.