background
|
|
Linux
Linux Support
A small area on the internet for Linux Support.
More icon

Games
Ruffnecks Gaming Gaming for everyone
More

Tombstone
Tombstone Tuning Home of tuning, projects and fast cars and boats.
More
|
|
Up Image
Navigation
Search this Site
Enter your search terms

Site Breadcrumb - You are here
|
Thau's JavaScript Tutorial
Lesson 2

by Thau!

Page 5 — if-then Branching

What "if-then" statements do is allow your program to behave very differently depending on what a user inputs. For example, you could write a script that would act one way toward you and a different way toward everyone else. Here's the basic form of an if-then statement:

if (some condition is true)
{ 
    do something;
    do something;
    do something;	
}

The important parts of this structure are:

  • It starts with the word "if" (if must be lowercase).
  • There is a condition in parentheses that is either true or false.
  • There is a set of statements that should be executed if the condition is true. These statements go between curly brackets.

Remember, spacing is only there to make the script more legible. You can put the entire if-then statement on one line if you want, but that would be hard to read.

Here's an example of an if-then statement in action.

next page»