Estou tentando implementar o numero de tentativas no jogo advinha numero juntamente com o input e o button.
Porem quando insiro um numero no input e clico no botao Advinha, o loop é executado 3 vezes em 1 clique.
Como posso fazer com que o loop apenas some o numero de tentativas?
Esse é o meu codigo:
function pulaLinha() {
  document.write("<br>");
  document.write("<br>");
}
function mostra(frase) {
  document.write(frase);
  pulaLinha();
}
function sorteia(n) {
  return Math.round(Math.random() * n);
}
var numeroPensado = sorteia(10);
var button = document.querySelector('button'),
    input = document.querySelector('input');
    input.focus();
function verifica() {
  var tentativas = 0;
  var chute = input.value;
  while(tentativas <= 3) {
    if(chute === numeroPensado) {
      mostra("Acertou!");
      break;
    } else if(chute !== numeroPensado) {
      mostra("Errou!");
      tentativas++;
      input.focus();
      if(tentativas === 3) {
        mostra("GAME OVER!");
        break;
      }
    }
  }
}
button.onclick = verifica; 
             
            