ttomasko
Programmer
- Aug 6, 2008
- 28
Hello,
I want to search through an array to make sure all the elements are the same. If so, I want there to be one alert to the user, not as many alerts as there are elements. But if one or more elements do not meet a condition, I want an alert for each of those elements.
Below is the script. In the array here all the elements are "b." I get five alerts when I really only want one. But if I change two of the elements to say "c" and "d", I want just two alerts for those elements. I want to ignore all the "b" elements.
How can I make this work?
Thanks,
Tom
var a = new Array ("b","b","b","b","b");
for(var i = 0; i < a.length; i++){
if(a =="b"){
alert("No problems, everything is b.");
}//end if
else if(a !="b"){
alert("OH oh, you have a "+a+" in the array.");
}//end else if
}//end for
I want to search through an array to make sure all the elements are the same. If so, I want there to be one alert to the user, not as many alerts as there are elements. But if one or more elements do not meet a condition, I want an alert for each of those elements.
Below is the script. In the array here all the elements are "b." I get five alerts when I really only want one. But if I change two of the elements to say "c" and "d", I want just two alerts for those elements. I want to ignore all the "b" elements.
How can I make this work?
Thanks,
Tom
var a = new Array ("b","b","b","b","b");
for(var i = 0; i < a.length; i++){
if(a =="b"){
alert("No problems, everything is b.");
}//end if
else if(a !="b"){
alert("OH oh, you have a "+a+" in the array.");
}//end else if
}//end for