'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;

    } 
}


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source