Practice: Run "Hello World"

Now, let's run your first JavaScript program. You can use an online editor or an editor of your choice. You'll create a page that displays the text "Hello World" in an alert box.

Here are the directions using the js online editor or you can use an editor of your choice.

1) Select the "Create new code" button. 

2) Copy and paste the following code into the editor window. 

3) Select the "Run code" button.

<!DOCTYPE html>
<html lang="en">
 <head>
 <title>My First JavaScript Example</title>
 <script>
 alert("Hello World!");
 </script>
 </head>
 <body style="background-color: #F22;">
 <p style = "font-size: 40px;">This the content of the webpage </p>
 </body>
</html>


Congratulations! You ran your first JavaScript program. Everything between the <script></script> was executed as JavaScript and you should see a small window with the words "Hello World!" 

What does the CSS code do? Using CSS, the background color for the webpage is "red" and the text is 40 pixels.

TODO: Try adding your own word or phrase to the alert line between the parentheses ( ).  Remember to enclose your word or phase in double quotes " ". 



Source: Mozilla, https://developer.mozilla.org/en-US/docs/Learn/HTML/Howto/Use_JavaScript_within_a_webpage
Creative Commons License This work is licensed under a Creative Commons Attribution-ShareAlike 2.5 License.

Last modified: Tuesday, October 4, 2022, 1:27 PM