Hi, can someone help me with this function, i cannot see what its wrong:
$().ready(iniciar);
function iniciar(){
$("#btnMostrar1").click(procesarEjercicio2);
}
var contador=0;
var respuesta;
var pos=0;
function procesarEjercicio2(){
var entrada=$("#textTexto").val();
var busqueda=$("#textLetra").val();
for(pos=0; pos<entrada.length; pos++){
if(entrada[pos]===busqueda);
contador++;
if(contador===0){
respuesta="No se a encontrado " + busqueda + " ";
else if(contador===1){
respuesta=" " + busqueda + " se ha encontrado una vez";
else respuesta=" " + busqueda + " se ha encontrado" + contador + " veces";
$("#pResultado1").html(respuesta);
}
}
}
}
And this is the HTML
<div>
<h1>Ejercicio2</h1>
<label for="textTexto">Texto</label>
<input type="text" id="textTexto"><br>
<label for="textLetra">Letra</label>
<input type="text" id="textLetra"><br>
<input type="button" id="btnMostrar1" value="Mostrar1">
<p id="pResultado1"></p>
</div>
Any suggestion?? thanks