Skip to content

Instantly share code, notes, and snippets.

@xola139
Created May 14, 2018 00:43
Show Gist options
  • Save xola139/cc43f9726d3a1b464496041ee6ac7c2e to your computer and use it in GitHub Desktop.
Save xola139/cc43f9726d3a1b464496041ee6ac7c2e to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html>
<body>
<p>Click the button to display the position of the element "Apple":</p>
<button onclick="myFunction()">Try it</button>
<p id="demo"></p>
<script>
function myFunction() {
var fruits = "Apple Mango";
var a = fruits.indexOf("Apple");
a = "esto es un POTOSI México texto";
var res= validaCiudad(a);
document.getElementById("demo").innerHTML = res;
}
var ciudades = ['AGUASCALIENTES','BAJA_CALIFORNIA','BAJA_CALIFORNIA_SUR','CAMPECHE','CHIAPAS','CHIHUAHUA',
'COAHUILA','COLIMA','CDMX','ESTADO','DURANGO','GUANAJUATO','GUERRERO','JALISCO','MICHOACÁN','MICHOACAN','MORELOS','NAYARIT','LEÓN','LEON','OAXACA','PUEBLA','QUERÉTARO','QUERETARO','QUINTANA','POTOSÍ','POTOSI','SINALOA','SONORA','TABASCO','TAMAULIPAS','TLAXCALA','VERACRUZ','YUCATÁN','YUCATAN','ZACATECAS','XALAPA','CANCUN','CANCÚN']
var validaCiudad = function(texto){
var len = ciudades.length;
for(var i = 0 ; i < len;i++)
{
if(texto.indexOf(ciudades[i])> -1){
switch (ciudades[i]) {
case "ESTADO":
return "ESTADO DE MÉXICO";
break;
case "MICHOACAN":
return "MICHOACÁN";
break;
case "QUINTANA":
return "QUINTANA ROO"
break;
case "LEON":
return "LEÓN"
break;
case "POTOSÍ":
case "POTOSI":
return "SAN LUÍS POTOSÍ";
case "YUCATAN":
return "YUCATÁN";
break;
case "CANCUN":
return "CANCÚN";
break;
}
return ciudades[i] ;
}
}
return 'no existe';
}
</script>
<p><b>Note:</b> The indexOf method was introduced in JavaScript 1.6, and does not work in Internet Explorer 8 and earlier versions.</p>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment