Here's a little program that uses an array. An array is nothing more than a variable that can hold multiple values. In this example, the variable "myfriends" is set to hold multiple friend names. Be aware of this type of variable. You will see it quite a bit in the JavaScripts we will be using.
Example:
<script language="JavaScript" type="text/javascript"> //create the variable as an array - the same variable holds multiple values var myfriends = new Array() //assign values to the array //notice that we start at zero myfriends[0] = "Jennifer Lopez" myfriends[1] = "Salma Hayak" myfriends[2] = "Beyonce Knowles" myfriends[3] = "Angelina Jolie" myfriends[4] = "Jessica Alba" myfriends[5] = "Halle Berry" //at this point the variable holds 6 values. </script>
Let's use another array variable to show how my students are doing. Here's the result of looping through the mystudents array:
There are 8 students in trouble!
Ariel is in danger of failing!
Alicia is in danger of failing!
Jose is in danger of failing!
Lorenzo is in danger of failing!
Edwin is in danger of failing!
Raul is in danger of failing!
Tony is in danger of failing!
Zack is in danger of failing!
Edwin needs after-school tutoring!