html - Javascript workout error with array elements -


i curious know how alert massage punting element number (brazil 6) array instead of of putting name of countries. have tried in several ways not working.

html:

<body>     <div></div>  </body> 

javascript :

var cleancities = ["argentina" , "brazil", "canada ", "denmark"]; var visit = prompt("what city?"); var numlength = cleancities.length; var matchfound = false;  (i=0; i<numlength ; i++)      if (visit === cleancities[i]){          matchfound = true;         alert ("it nice city")         break;      }      if (matchfound === false){         alert ("it not in list");     } 

first, clean braces , tabbing:

var cleancities = ["argentina" , "brazil", "canada ", "denmark"]; var visit = prompt("what city?"); var numlength = cleancities.length; var matchfound = false;  (i=0; i<numlength ; i++) {     if (visit === cleancities[i]) {         matchfound = true;         alert ("it nice city")         break;     } }  if (matchfound === false){     alert ("it not in list"); } 


to length of string:

"brazil".length 

outputs: 6


Comments

Popular posts from this blog

c++ - OpenCV Error: Assertion failed <scn == 3 ::scn == 4> in unknown function, -

php - render data via PDO::FETCH_FUNC vs loop -

The canvas has been tainted by cross-origin data in chrome only -