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. Inside our previous HTML code let’s insert a set of script tags with
console.log('I am an external script'). So our example.js file should look like:
As long as everything was entered 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. However if the file was in a different location or named incorrectly our browser would try to load the file, but would error instead. This would look like:
And our console.log of course would never show.
OK, so I 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.