Hello, day 1 javascript noob here. I can’t get my javascript script code to run in my chrome console or using my visual studio codes terminal.
I’m trying to use visual studio code to write javascript. I’ve made a folder and inside the folder, I have two files index.html and index.js. I also have node installed.
index.html contents:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<h1>Hello World2</h1>
<script>src="index.js"</script>
</body>
</html>
index.js contents:
console.log('hello');
I then right-click my HTML file and click open with live server as I have the addon installed. But when I check the console on chrome I can’t see anything there.
If I try and run the code using visual studio codes terminal, by typing $node index.js I get this error:
+ $node index.js
+ ~~~~~~~~
Unexpected token 'index.js' in expression or statement.
+ CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordException
+ FullyQualifiedErrorId : UnexpectedToken
I’ve removed adblocker from chrome as well.
I am completely dumbfounded and have no idea how to fix this. Any help would be amazing.