Hello! I want to say thanks in advance for all the help you guys may provide. As you can definitely tell, I am new to JavaScript. I am using the JavaScript Bible, Six Edition. In chapter 7 (JavaScript Tutorial, Programming Fundamentals, Parallel Arrays), the book gives an example of the following parallel array:
var USStates = new Array(4);
USStates[0] = “Alabama”;
USStates[1] = “Alaska”;
USStates[2] = “Arizona”;
var stateEntered = new Array(4);
stateEntered[0] = 1819;
stateEntered[1] = 1959;
stateEntered[2] = 1912;
Later the book gives an example of a function which will give the user the ability to search within the array and find out when did the State entered the Union. So far, I think I have a good understanding of the array, the “onclick” element calling the function; however, I am stuck with the “if” portion of the function. I am trying to read and understand the explanation provided in the book, but I still don’t understand what the “[i]” within the “if” portion does or why it is there. The function is below:
function getStateDate() {
var selectedState = document.getElementById(“entry”).value;
for (var i = 0; i < USStates.length; i++) {
if (USStates[i] == selectedState) {
break;
}
}
alert(selectedState + ” entered the Union in ” + stateEntered[i] + “.”);
}
Again, thanks in advance for your help.