Make your own free website on

Quick glossary


Assigning Variables

var question = prompt("You're question here","You're default value here, or blank if no default wanted")
Or you can just assign a variable any value you want
var question = "answer";
Text variables go in qoutes
var number = 18543;
number variables do not

Comparing Variables

Checking for one value
if (question == "answer") { Do these intructions }
else { do these intructions if the variable did not = answer}

That statement will check for one text response and then follow whatever instructions you have placed in the brackets if the variable equaled a certain value. If it did not it will follow the instructions after the else statement.

You could use the same statement for a number argument, a number argument is not usually in qoutes.

How to test to see if it doesn't equal a value.
if (age != 27){ Do these instructions }

Testing for multiple possibilities.
if ((question == "answer") || (question == "different answer")) {Do these instructions}

if ((name == "answer") && (age == 27)){Do these instructions} As you can see in multiple variable comparisons there are two ( ( before the first test, one after the first test, one before the second test and two after the second test.
if (variable != "answer") {do these instructions} the instructions will be followed if the variable does not equal a certain value


Adding things to a variable

You can add things or create new variables buy doing these things
var welcome = ("Weclome to my page "+name);
var myage = 27;
var agedif = (age-myage);
var agedif = (myage-age);
In the welcome variable took some text and added the name variable to the end of the text.
The number variables could be used to test and see the difference in a persons age and your age. You would first need to test and see if they are older or younger and then use wich ever version of agedif would produce the results you were looking for.

You could add html to a variable for use in the document.writeln(contents) statement.

var welcome = ("<center><h2>Welcome to my page </h2></center>" +name);


Writing directly to your page

The statement for writing onto your page instead of using the alert is as follows
document.writeln("Put your text in the qoutes, including html tags"+variables out of qoutes) Line breaks in text boxes and alerts. If you use the <br> tag in a text box or alert message it will not work as it will in the writeln statements. Here you have to use this \n it's not the / slash you use to close html tags but the opposite direction plus an n.

|| index||page 1||page 2||page 3||page 4||page 5||page 6||page 7||Page 8||