Post by Sora on Nov 4, 2011 12:42:11 GMT -5
Lesson Three:
VARIABLES
Welcome to yet, another lesson! You don't know it, but you have had experience with variables already! The word "myname" in the last lesson was a variable. Here's a short introduction to what a variable is.
A variable can be like this: 5="x". This shows now that 5 has a value of x. Can we use a word instead of a number? Sure! Like this: myname= "x". Can we use a number instead of a word or letter? Sure! Again, like this: myname= "bob". Now, myname has a value of bob.
Now to use this new information to make this:
Does this have to be Kingdom Hearts and Sora? Nope. You can use whatever.
Now, let's make a popup window that says "Hello Sora!" Again, you can customize what I do. Actually, you should customize it so you can call it your own. Now, let's do this.
Now, what we put in myname (we put sora in) will go after the word "hello ". If you want it to say something else you'd put something else in front, back, or both around the word myname. Here's and example: ("You know, "+myname+" is awesome!");
Now it will say "You know, Sora is awesome!". Let's save this and try it... As always, save a .html file!
VARIABLES
Welcome to yet, another lesson! You don't know it, but you have had experience with variables already! The word "myname" in the last lesson was a variable. Here's a short introduction to what a variable is.
A variable can be like this: 5="x". This shows now that 5 has a value of x. Can we use a word instead of a number? Sure! Like this: myname= "x". Can we use a number instead of a word or letter? Sure! Again, like this: myname= "bob". Now, myname has a value of bob.
Now to use this new information to make this:
<html>
<head>
<title></title>
<script type="text/javascript">
function HelloWorld()
{
kingdom hearts = "sora";
alert(myname);
}
</script>
</head>
<body>
<a href="javascript:HelloWorld()">Hello</a>
</body>
</html>
Does this have to be Kingdom Hearts and Sora? Nope. You can use whatever.
Now, let's make a popup window that says "Hello Sora!" Again, you can customize what I do. Actually, you should customize it so you can call it your own. Now, let's do this.
<html>
<head>
<title></title>
<script type="text/javascript">
function HelloWorld()
{
kingdom hearts = "sora";
alert("Hello "+myname);
}
</script>
</head>
<body>
<a href="javascript:HelloWorld()">Hello</a>
</body>
</html>
Now, what we put in myname (we put sora in) will go after the word "hello ". If you want it to say something else you'd put something else in front, back, or both around the word myname. Here's and example: ("You know, "+myname+" is awesome!");
Now it will say "You know, Sora is awesome!". Let's save this and try it... As always, save a .html file!