La siguiente página realizará un conteo de las consonantes N, M y Ñ devolviéndole al usuario la cantidad existente de cada una de manera individual.
Código:
<html>
<head>
<title>Contar NMÑ</title>
</head>
<script>
function procesar()
{
var v_texto = document.getElementById("texto").value;
n = v_texto.length;
var totaln = 0;
var totalm = 0;
var totalñ = 0;
var sw = 0;
for(i=0;i<n;i++)
{
c = v_texto.charAt(i);
if(c=="n")
{
totaln++;
sw++;
}
if(c=="m")
{
totalm++;
sw++;
}
if(c=="ñ")
{
totalñ++;
sw++;
}
if(c=="N")
{
totaln++;
sw++;
}
if(c=="M")
{
totalm++;
sw++;
}
if(c=="Ñ")
{
totalñ++;
sw++;
}
numn.value=totaln;
numm.value=totalm;
numñ.value=totalñ;
}
if(sw==0)
{
alert("No existen letras n, m ó ñ");
}
}
</script>
<body bgcolor=lightgreen>
<h1><b><center>PROGRAMA CONTAR LETRAS N - M - Ñ</h1></b></center><p>
<center>Ingrese Texto:
<input type="text" name="texto" id="texto"><p>
Número de Letras N:
<input type="text" name="na" id="numn"><p>
Número de Letras M:
<input type="text" name="ne" id="numm"><p>
Número de Letras Ñ:
<input type="text" name="ni" id="numñ"><p>
<input type="button" value="Procesar" Onclick="procesar()"></center>
</body>
</html>
No hay comentarios:
Publicar un comentario