Loops w/Additional Coding

Check if your city is one of the cleanest cities.

Code Example

 <script>
  var cityToCheck = prompt("Enter your city name to find out if it's on the Cleanest Cities list", "Honolulu");
  var cleanestCities = ["Cheyenne", "Santa Fe", "Tucson", "Great Falls", "Honolulu"];
  var worstCities = ["Los Angeles", "New York", "Chicago", "Detroit", "Flint"];
  var numElements = cleanestCities.length;
  var matchFound = false;

    for (var i = 0; i < numElements; i++) {
      if (cityToCheck === cleanestCities[i]) {
        matchFound = true;
        alert("It's one of the cleanest cities");
        document.write("It's one of the cleanest cities");
        break;
      }
    }

   var numElements2 = worstCities.length;
   var matchFound2 = false;

    for (var j = 0; j < numElements2; j++) {
      if (cityToCheck === worstCities[j]) {
        matchFound2 = true;
        alert("Oh...I'm sorry. Have you considered moving?");
        document.write("Oh...I'm sorry. Have you considered moving?");
        break;
	   }
    }

   if (matchFound === false && matchFound2 === false) {
     alert("Sorry, your city's not on the list");
     document.write("Sorry, your city's not on the list");
   }
  </script>