La página del siguiente ejemplo es una que utiliza las funciones de manejo de strings para contabilizar mediante un filtro lógico las vocales presentes en el texto que se ingrese.
Código:
<html>
<head>
<title>Contar Vocales</title>
</head>
<script>
function procesar()
{
var v_texto = document.getElementById("texto").value;
n = v_texto.length;
var total = 0;
var sw = 0;
for(i=0;i<n;i++)
{
c = v_texto.charAt(i);
if(c=="a"||c=="e"||c=="i"||c=="o"||c=="u")
{
total++;
sw++;
}
if(c=="A"||c=="E"||c=="I"||c=="O"||c=="U")
{
total++;
sw++;
}
resultado.value=total;
}
if(sw==0)
{
alert("No existen vocales");
}
}
</script>
<body bgcolor=lightgreen>
<h1><b><center>PROGRAMA CONTAR VOCALES</h1></b></center><p>
<center>Ingrese Texto:
<input type="text" name="texto" id="texto"><p>
Número de Vocales:
<input type="text" name="vocales" id="resultado"><p>
<input type="button" value="Procesar" Onclick="procesar()"></center>
</body>
</html>
No hay comentarios:
Publicar un comentario