Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

238
Vistas
2 attemps quiz but cant redirect back to quiz after showing result the first time

Im trying to do quiz with HTML and Javascript where users are allowed 2 attempts at the quiz. When users finish and submit the quiz answer, a result.html will pop up with score and attempt. After the first attempt, the user can use a button to redo the quiz and the button will disappear after the second attempt. But I cant get it to redirect back to the quiz after showing the result the first time.

Quiz.js

function showInfo() {
    if(sessionStorage.attempt == undefined){
        var attempt = 1;
        document.getElementById("attempt").textContent = attempt;
        getInfo();
        sessionStorage.attempt = attempt + 1;
    }
    else {
        document.getElementById("attempt").textContent = sessionStorage.attempt;
        getInfo();
        document.getElementById("btn-try").style = "DISPLAY:none";
    }
}

I tried to limit the attempt in this function then called it in the init() function however, the result.html just refresh and the attempt goes up to 2.

function tryAgain() {
    window.location= "quiz.html";
}



function init() {
    if (document.getElementById("quizform") != null) 
    {
        var regForm = document.getElementById("quizform");
        regForm.onsubmit = validate;
        
    } else {
        showInfo();   
        document.getElementById("btn-try").onclick = tryAgain;

    } 
}
about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda