Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community!
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
Siavash Gheifardi
12,510 PointsLoop not working.
var userCity=prompt("what city are you from?")
var numElements = cleanestCities.length;
var matchFound = false;
var cleanestCities = ["Louisville", "New York", "Mexico City", "Japan"];
for (var i=0; i<numElements; i++) {
if(userCity === cleanestCities[i]) {
matchFound = true;
alert("it's one of the cleanest cities")
break
}
}
if (matchFound) ===false) {
alert("It's not on the list");
}
what am i doing wrong?

Siavash Gheifardi
12,510 PointsI just dont understand why the prompt does not pop.
3 Answers

Steven Parker
224,849 Points There's a couple of issues preventing your code from running:
- On line 2, you reference cleanestCities before it has been declared. Place this line after that is done.
- On line 12, you have a stray closing parenthesis, as Jeremy indicated.
Optionally, you could condense line 12 to this:
if (!matchFound) {

Jeremy Hill
29,567 Pointsplace a ';' at the end of that line.

Steven Parker
224,849 Points Semicolons at the end of a line are good practice, but they are completely optional.

Sean T. Unwin
28,686 PointsThe variable, var numElements = cleanestCities.length;
needs to be after cleanestCities
has been declared.
Unmatched closing parenthesis at if (matchFound) ===false) {
.
Jeremy Hill
29,567 PointsJeremy Hill
29,567 PointsIt looks like you have an extra parenthesis in this line: if (matchFound) ===false) {. Remove the one after the matchFound.