Javascript code not executing

I am very new to JavaScript.

I had written a simple hello world code in Text Editor and saved the file as helloworld2.html and when opended the file through Google Chrome on Macbook Pro but the browser simply shows the code. I checked the JS option on the Chrome is enabled.

Here is the code :

Please Help :smile:

1 Like

you need two things:

a html file
a js file

in the html file, use <script> to load the JS file.

A html file only understand html “syntax”.

1 Like

What part of the below code needs to be in the html file and js file ?

<!DOCTYPE HTML>

<html>

<body>

<script>

alert(‘Hello, World!’)

</script>

</body>

</html>

1 Like

you can indeed also use <script></script> to have js code embedded within the html file.

seems to work fine when i i make a html file with that content, i get an alert.

1 Like

Are there any pre-requisite check before running JS? 09%20PM

see the output how it runs on my machine.

1 Like

the html code shouldn’t be visible. Ensure the html document is encoded as such, it appears to be plain text at the moment.

the command line has a file command, can you run:

file helloworld2.html

to ensure the file is understood as html file?

1 Like