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
Post a Comment