HTML File(firstHTML.html)
<!DOCTYPE html>
<html>
<body>
<h2>My First Web Page</h2>
<p id="demo">First Paragraph</p>
<p id="demo2">Second Paragraph should be something different</p>
<script src="myScript.js">
show3();
</script>
</body>
</html>
JavaScript File(myScript.js)
let show3 = function() {
document.getElementById(‘demo2′).innerHTML=’I am trying to change the second paragraph using an anonymous function in an external JS file’;
};
I was expecting for the show() function to run since it’s below the
tag. I am still learning about javascript scope so it’s entirely possible that anonymous functions don’t have a global scale and so my function won’t run but why is my question. Thank you all in advance.