Assets/js/logic.js
// Event to compare choices with answer
Event to compare choices with answer
Event to compare choices with answer
function compare(event) {
    var element = event.target;
    if (element.matches("li")) {
        var createDiv = document.createElement("div");
        createDiv.setAttribute("id", "createDiv");
        if (element.textContent == question[questionIndex].answer) {
            score++;
            createDiv.textContent = "Correct! The answer is:  " + question[questionIndex].answer;
        } else {
            secondsLeft = secondsLeft - penalty;
            createDiv.textContent = "Wrong! The correct answer is:  " + question[questionIndex].answer;
        }
    }
    questionIndex++;
    if (questionIndex >= question.length) {
        allDone();
        createDiv.textContent = "End of quiz!" + " " + "You got  " + score + "/" + question.length + " Correct!";
    } else {
        render(questionIndex);
    }
    questionDiv.appendChild(createDiv);
}
function compare ( event ) { var element = event . target ; if ( element . matches ( "li" ) ) { var createDiv = document . createElement ( "div" ) ; createDiv . setAttribute ( "id" , "createDiv" ) ; if ( element . textContent == question [ questionIndex ] . answer ) { score ++ ; createDiv . textContent = "Correct! The answer is:  " + question [ questionIndex ] . answer ; } else { secondsLeft = secondsLeft - penalty ; createDiv . textContent = "Wrong! The correct answer is:  " + question [ questionIndex ] . answer ; } } questionIndex ++ ; if ( questionIndex >= question . length ) { allDone ( ) ; createDiv . textContent = "End of quiz!" + " " + "You got  " + score + "/" + question . length + " Correct!" ; } else { render ( questionIndex ) ; } questionDiv . appendChild ( createDiv ) ; }
Event to compare choices with answer
Event to compare choices with answer
// Correct condition  // Correct condition  // Will deduct -5 seconds off secondsLeft for wrong answers // Question Index determines number question user is on // All done will append last page with user stats