-3

i wrote this html document and the script isn't running

alert("my name")
<html>

<body>
  fvbnhjm
  <script type="text\javascript" src="JavaScript.js">
  </script>
</body>

</html>

i installed code runner in vs code and the only thing that i added to settings.json is this

"code-runner.saveAllFilesBeforeRun": true,
"code-runner.saveFileBeforeRun": true,
"code-runner.executorMapByFileExtension": {

    ".js": "cd $dir $$ start $fileName",
    ".html": "cd $dir && start $fileName"
},

javascript isn't disabled in my browser, i don't need node.js here but i installed it

  • 1
    Remove the type="text\javascript" from the script tag, ensure that the JavaScript.js is on the same folder and try again. – Kostas Minaidis Sep 26 '22 at 18:39
  • 1
    `text\javascript` isn't the correct type for javascript. You can omit the type attribute, but if you're going to include it you need a `/` instead of `\\`. – ray Sep 26 '22 at 18:39
  • @rayhatfield thank you very much, add this as an answer – Moaaz Mostafa Sep 26 '22 at 18:55

2 Answers2

0

text\javascript isn't the correct type for javascript.

You can omit the type attribute, but if you're going to include it you need a / instead of \.

ray
  • 26,557
  • 5
  • 28
  • 27
0

Let's see your folder structure, make sure you have type a valid path to your js file.

Looking for simple way to type the path? Just right click on your js file and click copy path. Then, paste it in src="file.js".

<html>

<body>
  fvbnhjm
  <script type="text/javascript" src="JavaScript.js">
  </script>
</body>

</html>

You can read more about it in this thread.

Thank you