La página mostrada a continuación, similar a la anterior, cuenta las vocales de manera individual utilizando procesos lógicos separados para la detección y filtración de las vocales agrupando cada una ya sea mayúscula o minúscula en su variable respectiva.
Código:
<html>
<head>
<title>Contar Vocales</title>
</head>
<script>
function procesar()
{
var v_texto = document.getElementById("texto").value;
n = v_texto.length;
var totala = 0;
var totale = 0;
var totali = 0;
var totalo = 0;
var totalu = 0;
var sw = 0;
for(i=0;i<n;i++)
{
c = v_texto.charAt(i);
if(c=="a")
{
totala++;
sw++;
}
if(c=="e")
{
totale++;
sw++;
}
if(c=="i")
{
totali++;
sw++;
}
if(c=="o")
{
totalo++;
sw++;
}
if(c=="u")
{
totalu++;
sw++;
}
if(c=="A")
{
totala++;
sw++;
}
if(c=="E")
{
totale++;
sw++;
}
if(c=="I")
{
totali++;
sw++;
}
if(c=="O")
{
totalo++;
sw++;
}
if(c=="U")
{
totalu++;
sw++;
}
numa.value=totala;
nume.value=totale;
numi.value=totali;
numo.value=totalo;
numu.value=totalu;
}
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 Letras A:
<input type="text" name="na" id="numa"><p>
Número de Letras E:
<input type="text" name="ne" id="nume"><p>
Número de Letras I:
<input type="text" name="ni" id="numi"><p>
Número de Letras O:
<input type="text" name="no" id="numo"><p>
Número de Letras U:
<input type="text" name="nu" id="numu"><p>
<input type="button" value="Procesar" Onclick="procesar()"></center>
</body>
</html>
No hay comentarios:
Publicar un comentario