1

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.

2
  • 1
    extra comma at the end of array Commented Jan 25, 2014 at 20:07
  • And another one before var. This fiddle doesn't compile... Commented Jan 25, 2014 at 20:08

1 Answer 1

6

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!");
    }

jsFiddle Demo

Sign up to request clarification or add additional context in comments.

1 Comment

Yup, silly mistake! Thanks for finding it and pointing it out.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.