js_1 – Hello World

JavaScript: A scripting programming language most commonly used to add interactive features to web pages. If you want your web pages to do anything fancy, or be actually useful for interacting with clients, you need to add script to it, like JavaScript. In spite of the similarity in name to Java, it is not related to the Java programming language.

A) Hello World in Javascript

  1. Create a new document in Notepad ++
  2. Type out the following Code – notice that we are still creating an html page, but we are adding javascript to it:

(Remember to add indents and spacing for good programming style.)

<html>

<body>

<script type=”text/javascript”>

document.write(“Hello World!”);

</script>

</body>

</html>

  1. Save the file as hello2a.html
  2. Open the file from a web browser to preview it

Note: It still shows a web page with Hello World, but we wrote it with javascript instead of just html. Notice we used the document.write command to write output to our page.

 

B) Hello World with a JavaScript alert box

Now we will create a 2nd web page, which uses Java Script to display hello world, but this time we will use a JavaScript alert box instead.

  1. Create a new document in Notepad ++
  2. Type out the following code
  3. Save it as hello2b.html

<html>

<body>

<script type=”text/javascript”>

alert(“I am an alert box!!”);

</script>

</body>

</html>

Preview your file by running it with a web browser.

Note: It still shows a web page with your message, but the message appears in a pop-up box.

____________________________________________________________________________________________________

 ASSIGNMENT

After working through the above examples…

Use Notepad++ or some such program and create an HTML javascript that:

  • uses the code from section B above
  • has text of your own choice

Save your script file as home2.html and run it to test it.  Then hand in your code as a .txt file.

____________________________________________________________________________________________________