Reputation: 305
Okay, so I am working on a weather application, and I wrote the following test code to verify that the user entered a valid state abbreviation:
var input = prompt("What state are you in?");
var lower = input.toLowerCase();
var categories = [
"ma",
"ny",
"ct",
"ri",
],
var found = $.inArray(lower, categories);
if (found > -1) {
alert("Cool!");
}
else {
alert("Oh no!");
}
But for some reason, it doesn't work.
Take a look: http://jsfiddle.net/B24Bg/
Does anyone know why this is? I probably just made a silly mistake, but any help would be greatly appreciated.
Upvotes: 1
Views: 10650
Reputation: 16990
Check your console window in your browser, press F12, there are errors.
The comma after ] should be a semi-colon:
var input = prompt("What state are you in?");
var lower = input.toLowerCase();
var categories = [
"ma",
"ny",
"ct",
"ri"
];
var found = $.inArray(lower, categories);
if (found > -1) {
alert("Cool!");
}
else {
alert("Oh no!");
}
Upvotes: 6