Javascript: Conditional Statements

The Javascript engine reads your document from top to bottom, assigning variables and executing statements as it goes. Often we only want to execute certain statements in our program based on a particular condition. Using a conditional test is a very common way to do this.


var billsAge = 60;
var marysAge = 60;
var tedsAge = 52;

if(billsAge == tedsAge){
  alert("Bill is the same age as Ted");
}else if(billsAge == marysAge){
  alert("Bill is the same age as Mary");
}else{
  alert("No one is the same age");
}