-3
<!Doctype html>     
<html>     
<title>JavaScript Tutorial</title>     
<body>     
<script language = "javascript">     
var cleanCities = ["Cheyenne ","Santa Fe ","Tucson ","Great Falls ","Honolulu"];     
var cityToCheck = "Tucson";

if(cityToCheck === cleanCities[i]) {     
  alert("You are clean");     
} 
</script> 

</body> 

</html> 

I cannot find the errors

it's a javascript code

<!Doctype html> 
<html> 
<title>JavaScript Tutorial</title> 
<body> 
<script language = "javascript"> 
var cleanCities = ["Cheyenne ","Santa Fe ","Tucson ","Great Falls ","Honolulu"]; 
var cityToCheck = "Tucson"; 
if(cityToCheck === cleanCities[i]) { 
  alert("You are clean"); 
} 
</script> 
</body> 
</html> 

It says there is some problem in line 14

Nick Parsons
  • 45,728
  • 6
  • 46
  • 64

1 Answers1

1

Where is your for loop for which you're an index i? If its removed intentionally then Tucson in your array has a space in the end. Use trim method.

Also language = "javascript" is wrong, its usually type="text/javascript"

The code should be like below:

enter code here
var cleanCities = ["Cheyenne ","Santa Fe ","Tucson ","Great Falls ","Honolulu"];
var cityToCheck = "Tucson";
for(var i=0; i<cleanCities.length; i++) {
   if(cityToCheck === cleanCities[i].trim()){
    alert('you are clean');
   }
 }
Sagar Agrawal
  • 639
  • 1
  • 7
  • 17