Assets/js/logic.js
// All done will append last page
All done will append last page
All done will append last page
function allDone() {
    questionDiv.innerHTML = "";
    currentTime.innerHTML = "";
    var createH1 = document.createElement("h1");
    createH1.setAttribute("id", "createH1");
    createH1.textContent = "All Done!"
    questionDiv.appendChild(createH1);
    var createP = document.createElement("p");
    createP.setAttribute("id", "createP");
    questionDiv.appendChild(createP);
    if (secondsLeft >= 0) {
        var timeRemaining = secondsLeft;
        var createP2 = document.createElement("p");
        clearInterval(holdInterval);
        createP.textContent = "Your final score is: " + timeRemaining;
        questionDiv.appendChild(createP2);
    }
    var createLabel = document.createElement("label");
    createLabel.setAttribute("id", "createLabel");
    createLabel.textContent = "Enter your initials: ";
    questionDiv.appendChild(createLabel);
    var createInput = document.createElement("input");
    createInput.setAttribute("type", "text");
    createInput.setAttribute("id", "initials");
    createInput.textContent = "";
    questionDiv.appendChild(createInput);
    var createSubmit = document.createElement("button");
    createSubmit.setAttribute("type", "submit");
    createSubmit.setAttribute("id", "submit");
    createSubmit.textContent = "Submit";
    questionDiv.appendChild(createSubmit);
    createSubmit.addEventListener("click", function () {
        var initials = createInput.value;
        if (initials === null) {
            console.log("No value entered!");
        } else {
            var finalScore = {
                initials: initials,
                score: timeRemaining
            }
            console.log(finalScore);
            var allScores = localStorage.getItem("allScores");
            if (allScores === null) {
                allScores = [];
            } else {
                allScores = JSON.parse(allScores);
            }
            allScores.push(finalScore);
            var newScore = JSON.stringify(allScores);
            localStorage.setItem("allScores", newScore);
            window.location.replace("/highscores.html");
        }
    });
}
function allDone ( ) { questionDiv . innerHTML = "" ; currentTime . innerHTML = "" ; var createH1 = document . createElement ( "h1" ) ; createH1 . setAttribute ( "id" , "createH1" ) ; createH1 . textContent = "All Done!" questionDiv . appendChild ( createH1 ) ; var createP = document . createElement ( "p" ) ; createP . setAttribute ( "id" , "createP" ) ; questionDiv . appendChild ( createP ) ; if ( secondsLeft >= 0 ) { var timeRemaining = secondsLeft ; var createP2 = document . createElement ( "p" ) ; clearInterval ( holdInterval ) ; createP . textContent = "Your final score is: " + timeRemaining ; questionDiv . appendChild ( createP2 ) ; } var createLabel = document . createElement ( "label" ) ; createLabel . setAttribute ( "id" , "createLabel" ) ; createLabel . textContent = "Enter your initials: " ; questionDiv . appendChild ( createLabel ) ; var createInput = document . createElement ( "input" ) ; createInput . setAttribute ( "type" , "text" ) ; createInput . setAttribute ( "id" , "initials" ) ; createInput . textContent = "" ; questionDiv . appendChild ( createInput ) ; var createSubmit = document . createElement ( "button" ) ; createSubmit . setAttribute ( "type" , "submit" ) ; createSubmit . setAttribute ( "id" , "submit" ) ; createSubmit . textContent = "Submit" ; questionDiv . appendChild ( createSubmit ) ; createSubmit . addEventListener ( "click" , function ( ) { var initials = createInput . value ; if ( initials === null ) { console . log ( "No value entered!" ) ; } else { var finalScore = { initials : initials , score : timeRemaining } console . log ( finalScore ) ; var allScores = localStorage . getItem ( "allScores" ) ; if ( allScores === null ) { allScores = [ ] ; } else { allScores = JSON . parse ( allScores ) ; } allScores . push ( finalScore ) ; var newScore = JSON . stringify ( allScores ) ; localStorage . setItem ( "allScores" , newScore ) ; window . location . replace ( "/highscores.html" ) ; } } ) ; }
All done will append last page
All done will append last page
// Heading: // Paragraph // Calculates time remaining and replaces it with score // Label // input // submit // Event listener to capture initials and local storage for initials and score // Travels to final page