Javascript



Javascript Introduction



Javascript is a nice language to improve your website, it is used for more advanced website design. If you havent learned HTML already i recommend you take a look at my HTML section of the website before you start learning javascript as it may be too overwhelming for a beginner, but its your choice.

To start off i should introduce you to the basics of javascript, the stuff you will use most of the time.

Starting off:

<SCRIPT LANGUAGE="Javascript">

The above code is how you start out when you are writing javascript, it tells the computer to start using the javascript language.

Let me explain it: <SCRIPT> is a tag like all the other tags you've seen in HTML. It also has an attribute attached to it, the attribute called LANGUAGE= which is followed by "Javascript". This attributed tag says that we will now be scripting in the language, javascript, so now anything you write after it will be recognized as javascript. As many other tags that affect whatever is written after them, this uses an ending tag to tell the computer when to stop using the language, javascript. Can you guess what it is?

If you guessed </SCRIPT>, i think you are getting the hang of this!


Variables

Take a look at this code and see if you can understand whats going on.

<SCRIPT LANGUAGE="Javascript">

var people = 50;
var People = people*2;
var People_poor = 15;


The above code includes the SCRIPT tag as previously mentioned, and has a new element, variables.

A variable is used to store data, and the only way to retrieve the data is if it is given a name so that you may retrieve the data stored there later.

To make a variable first write "var", following it is the name of what you want your variable to be called (doing so helps you and others recognize what the use of your variables are) names are used for recognition as well as for retrieving data, kind of like names of people such as Mark or Ashley, they are used to recognize people, and if you were to look up somebody's name you would retrieve information stored about them.

After you have picked out a name that suits the variable's use, put an equal sign to tell what your variable is going to equal, then put what value you want stored in the variable, in this case it is a numerical value, you can also store text in variables, ill go over that in a little bit so stay tuned.

If you are thinking that the first and second variables, people and People, are the same thing! You are wrong. Variables are case-sensitive
-- Case sensitive means that if a letter in your word is capitalized it must also be capitalized later on to be recognized as the same variable or it will be considered as a variable completely different. If something is not case-sensitive it doesnt matter if its upper-case or lower-case it will be recognized as the same thing like PoWeR or power would be the same. --
The good thing about case-sensitive variables is that you can use multiple variables with the same word, you could have 8 different variables with one 3-letter word!!! ate,Ate,aTe,atE,ATe,aTE,ATE,AtE. I do not recommend doing this but it is an option and i am here to teach you all the options you have.

The second variable takes the value stored at people and multiplies it by 2, which would be 100.

The last variable gives an example of making a specific name variable. It tells us that we are talking about People but more specifically, the ones that are poor. To be specific in your variables i recommend using an underscore " _ " to seperate your words.

Now the semi-colon at the end of the variables is used to tell javascript that we are done with this line of code, think of it like the end tags in HTML.


Now for the storage of text in variables.

var website = "Typo Jester";

The series of text that is now stored in website, is Typo Jester, this is also called a string. If you are going to store a string in a variable remember to enclose it with quotations.


Next before we reach the finale of our introduction to javascript i must teach you about how to write on the body of your website using javascript.

In HTML to write in the body of your website all you had to do was enclose it with <p> and </p> or you could even just write without those two tags, as long as it was outside any tags or attributes it would show up on your document. But for javascript it is a little more picky with how things are done.

document.write("The amount of people we have is " + people);

Wow looks a little complicated right? This is completely new stuff so i will make sure i go over it thoroughly.

Let me explain what is happening here.
First we have the phrase document.write, that pretty much says to javascript that we want to write, and we want it to show up on our document (the website body). Then we have to enclose what we want to say in 2 parantheses
-- ("This is where we write what we want shown") --
When something is enclosed in quotations like in variables or in this case document.write, this is telling javascript to not see it as a javascript code anymore, but instead as HTML code (since javascript is within HTML). So now it will read it as an HTML code, if nothing is enclosed in a tag you will see it show up in the body of your website, and the good thing about this is you can now use tags from HTML, as long as its inbetween quotations.

But wait!! What are those plus signs doing there!
The plus sign is telling javascript that we are now going to add something to write on to our document but this time we dont want it to be seen as HTML code but instead javascript code again. In this case our code is a variable, if you recognize, that variable is from our previous explanation. It just so happens equals 50. And just like the variables, we end our bit of code with the semi-colon, ";".


Now that i showed you all for introduction let me show you them all in action!

<SCRIPT LANGUAGE="Javascript">

var people = 50;
var People = people*2;
var People_poor = 15;

var website = "Typo Jester";

document.write("The amount of people we have is " + people + ".<br>");

document.write("The amount of People we have is " + People + ".<br>");

document.write("The amount of People_poor we have is " + People_poor + ".<br>");

document.write("This website we are on is called " + website + " and it is great.<br>");

</SCRIPT>

That shows everything i have talked about so far and below is the result of it.





As you can see we write each line and then add on a period and a break tag at the end of them. They are within two quotation marks so that they will be seen as HTML code which will then write a period and then break to a new line. Breaking will make it so the lines all dont cram together onto one line and instead BREAK into seperate lines.


That is it for the introduction of javascript, if you didnt understand a word you can feel free to go over it again, but I recommend you go back to HTML lessons as i have went over a couple of things from the HTML section. Otherwise go on and check out more of javascript if you feel comfortable with it, i have many more lessons to show you, hope you enjoy.


Join Today
 
Join our Website's Jester Forum today!
Its FREE and easy......
Click Here
Advertisement
 
News
 
7-12-07
_____________________
Status: SITE OPENED

WELCOME!

Enjoy the STAY

If you enjoyed this page,
add 2 favorites or tell a friend

Daily Event
 
Fortune of the Day

Quick Search
 
Google:
Yahoo:
Excite:
Ads & News
 
 
39144 visitors
=> Do you also want a homepage for free? Then click here! <=