a little twist on the usual "finding string in an array" question:
I currently know how to find a string in an array, using a for loop and if statement. But what I want to do is return an option if no matching string can be found once iterating through the entire array. The obvious problem is that if I include an else option in my current if-statement, each iteration that there is no match moves to the else.
So basically, I want to scan through the entire array.. IF there's a match I want to print "abc" and if there is no match at all I want to print "xyz". How do I do this? Thanks (super novice here :)).
var guestList = [
"MANDY",
"JEMMA",
"DAVE",
"BOB",
"SARAH",
"MIKE",
"SUZY"
];
var guestName = prompt("Hello, welcome to The Club. What is your name?").toUpperCase();
for (var i=0; i<guestList.length; i++){
if (guestName === guestList[i]){
alert("Hi " + guestName + " You are on the list! Enjoy The Club");
}
}