JavaScript_02 - Hello World

Creating your first javascript program.

Pr-requisites: You'll need a text editor and a web browser for creating and executing javascript files.

Javascript code are embedded into an html file, so all the html tags are to be written again for creating each web page for running javascript. So a default page need to be created so that it can be copied and pasted and we can deal with just the part of javascript.

So, lets create our default html page:

default.html

<html>

<head>
<title>codeMystery</title>
</head>

<body>
<center><h1>Default</h1></center>
</body>

</html>

Download here: https://www.file-upload.com/oqq5dw3p0j50

Now that our default html document is created we can start writing our first javascript program.

Go to the head section of the html document start typing the following code:

<html>

<head>
<title>codeMystery</title>
</head>

<body onload="alert('Hello World!')">
<center><h1>Default</h1></center>
</body>

</html>

Download here: https://www.file-upload.com/6ogodzq0prb5

By opening the above code into the browser it will open an alert box saying 'Hello World!'.

Now we will create an external javascript file and call the function within our html document.

JS_02.html

<html>

<head>
<title>codeMystery</title>

<script type="text/javascript">
   function hello()
    {
        alert("Hello World!");
    }

</script>
</head>

<body onload="hello()">
<center><h1>Default</h1></center>
</body>

</html>

Download here: https://www.file-upload.com/rqyup4vo74uu

JS_02_01.js

function hello()
{
  alert("Hello World!");
}

Download here: https://www.file-upload.com/pwfhk15lrddx

JS_02_01.html

<html>

<head>
<title>codeMystery</title>

<script src="JS_02_01.js" type="text/javascript">

</script>

</head>

<body onload="hello()">
<center><h1>Default</h1></center>
</body>

</html>

Download here: https://www.file-upload.com/82v0597pttto

Comments

Popular Posts