2. Copy the following code and save it in
a text editor as hello.html
<html>
You can use any text editor of
<head> <title></title> your choice. I prefer
notepad ++
</head> http://notepad-plus-
plus.org/download/v6.2.html
<body>
</body>
</html>
3. Add script tags within head section
The scripts tags tell the <html>
<head>
browser that there is <title></title>
scripting contained
<script
between (in this case
type="text/javascript">
“javaScript”).
</script>
</head>
<body>
</body>
</html>
5. Let’s make a function
<html>
<head>
• A function executes a series <title></title>
of instructions.
<script type="text/javascript">
• We will start with an empty
shell function ()
{
}
</script>
</head>
<body>
</body>
</html>
6. Function name
<html>
<head>
We will name our <title></title>
<script type="text/javascript">
function HelloWorld.
function HelloWorld()
{
We will add an alert box alert ("Hello World!");
that say’s “Hello }
World!”
</script>
</head>
<body>
</body>
</html>
7. Function Structure
• The word function declares that there is a
function.
• The function name is HelloWorld.
• Parentheses () (has use we will get to later in
the course)
• {} curly brackets contain the set of instructions
8. Execute Function
<html>
<head>
Now that we have <title></title>
covered the function
<script type="text/javascript">
head tags, let’s make it
execute when we click function HelloWorld()
{
on a link. alert ("Hello World!");
}
</script>
Here is a generic link
that point nowhere: </head>
<body>
<a href="">Hello</a>
</body>
</html>
9. Execute Function
<html>
<head>
<title></title>
This will make it point
to our function <script type="text/javascript">
function HelloWorld()
{
alert ("Hello World!");
}
</script>
</head>
<body>
<a
href=" javascript:HelloWorld()">
Hello</a>
</body>
</html>
10. Your turn
After saving your
work, try opening
your
HelloWorld.html
file in your web
browser.
It should look like
this
11. Your first JavaScript
Congratulations, you just made your first
JavaScript!
There are two things I would like you to
remember:
1. JavaScript and Java are not the same thing.
2. JavaScript is case-sensitive!