Skip to content

How To Write Your First Javascript Program.

Your first program in JavaScript will teach you how you can display a message to the user when he visits your website, it is super simple, you should try it yourself.

First: Creating an HTML file:

First you need to create an HTML file which will have the name "index.html". After creating the file you write the current code inside it :

html
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
</head>
<body>
    
</body>
</html>

Second: Writing JavaScript code:

Inside the body tag (between <body> and </body>) you will create a script tag (<script></script>)
Inside that script tag you will start typing your code.
You enter the following line :
alert("message text");
The result will be the code below which will display a popup containing "message text" for the user when he enters the page.

html
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
</head>
<body>
<script>
    alert("message text");
</script>
</body>
</html>

To test your code you double click the "index.html" file you created and open it with your browser.

You will see a popup displayed like the one you will get when you click this button:



Thanks for reading, hope it was useful.