Post by Sora on Nov 3, 2011 19:14:53 GMT -5
JavaScript is a hard thing to learn if you don't know what HTML or UBBC is. If you are new to coding I suggest you try learning about those two styles of coding first, yet you do not have to.
Let's start with a traditional Hello World! Seems every programming tutorial begins with that.
Copy the following and save as hello.html
Then add script tags within the head section. The script tags tell the browser that some sort of scripting is contained between (in this case "javascript").
Again, our script tags are within the head section, not the body.
Now we'll make a function. A function does something. It executes a series of instructions. We'll start with an empty shell...
We'll name our function HelloWorld. We'll add that, and an alert box that say's "Hello World!"...
Notice how the function is structured. The word function declaring that it is in fact, a function. The function name - HelloWorld. The parentheses ( ), these have a use that we'll get into later, and the curly brackets - { } that contain the set of instructions.
So, that's it for the function in the head tags. It's just sitting there waiting for something to call it. How about we make it execute when we click on a link? Sounds good to me. Here's a generic link that points nowhere for now...
Well, look at that! Your very first JavaScript (well, maybe first)! I hope this was easy for you! You can start lesson two now since you understand this...
Let's start with a traditional Hello World! Seems every programming tutorial begins with that.
Copy the following and save as hello.html
<html>
<head>
<title></title>
</head>
<body>
</body>
</html>
Then add script tags within the head section. The script tags tell the browser that some sort of scripting is contained between (in this case "javascript").
<html>
<head>
<title></title>
<script type="text/javascript">
</script>
</head>
<body>
</body>
</html>
Again, our script tags are within the head section, not the body.
Now we'll make a function. A function does something. It executes a series of instructions. We'll start with an empty shell...
<html>
<head>
<title></title>
<script type="text/javascript">
function ()
{
}
</script>
</head>
<body>
</body>
</html>
We'll name our function HelloWorld. We'll add that, and an alert box that say's "Hello World!"...
<html>
<head>
<title></title>
<script type="text/javascript">
function HelloWorld()
{
alert ("Hello World!");
}
</script>
</head>
<body>
</body>
</html>
Notice how the function is structured. The word function declaring that it is in fact, a function. The function name - HelloWorld. The parentheses ( ), these have a use that we'll get into later, and the curly brackets - { } that contain the set of instructions.
So, that's it for the function in the head tags. It's just sitting there waiting for something to call it. How about we make it execute when we click on a link? Sounds good to me. Here's a generic link that points nowhere for now...
<html>
<head>
<title></title>
<script type="text/javascript">
function HelloWorld()
{
alert ("Hello World!");
}
</script>
</head>
<body>
<a href="">Hello</a>
</body>
</html>
Make it point to our function...
<html>
<head>
<title></title>
<script type="text/javascript">
function HelloWorld()
{
alert ("Hello World!");
}
</script>
</head>
<body>
<a href="javascript:HelloWorld()">Hello</a>
</body>
</html>
Well, look at that! Your very first JavaScript (well, maybe first)! I hope this was easy for you! You can start lesson two now since you understand this...