I've started playing around with JS but I'm having some trouble calling a function from an external file.
I've tried most solutions in other questions posted here but still cannot get the function to execute.
I have the following JS File (myjs.js):
console.log("Loaded JS");
//Startup function
function setup(){
console.log("Testing");
}
setup();
And here's the HTML which uses it:
<html>
<head>
<meta charset="UTF-8">
<link rel="stylesheet" href="mycss.css"/>
<script type="text/javascript" src="myjs.js"/>
</head>
<body>
<script type="text/javascript"> setup(); </script>
</body>
</html>
I've tried loading the script in the body and then calling the setup()
function, and expect to see the following in the console:
Loaded JS //From loading JS
Testing //From loading JS
Testing //Invoking setup
Instead I only see:
Loaded JS
Testing
What exactly am I doing wrong?
Thanks.