assets/js/app.js
//This function loads a question and choices into our DOM
This function loads a question and choices into our DOM
This function loads a question and choices into our DOM
function loadQuestion() {
    resetChoices();
    timeElapsed = 0;
    questionTimer = setInterval(function() {
        timeElapsed++;
    },1000);
    currentQuestion++;
    if (currentQuestion == questions.length) {
        return endQuiz();
    }
    currentQuestionInfo = questions[currentQuestion];
    questionText.innerHTML = currentQuestionInfo.title;
    for (var i = 0; i < currentQuestionInfo.choices.length; i++) {
        var newChoice = document.createElement('div');
        newChoice.setAttribute('class','choice');
        var newButton = document.createElement('button');
        newButton.setAttribute('class','btn btn-secondary');
        newButton.innerHTML = currentQuestionInfo.choices[i];
        newChoice.appendChild(newButton);
        choicesContainer.appendChild(newChoice);
    }
    questionContainer.style.display = "block";
}
function loadQuestion ( ) { resetChoices ( ) ; timeElapsed = 0 ; questionTimer = setInterval ( function ( ) { timeElapsed ++ ; } , 1000 ) ; currentQuestion ++ ; if ( currentQuestion == questions . length ) { return endQuiz ( ) ; } currentQuestionInfo = questions [ currentQuestion ] ; questionText . innerHTML = currentQuestionInfo . title ; for ( var i = 0 ; i < currentQuestionInfo . choices . length ; i ++ ) { var newChoice = document . createElement ( 'div' ) ; newChoice . setAttribute ( 'class' , 'choice' ) ; var newButton = document . createElement ( 'button' ) ; newButton . setAttribute ( 'class' , 'btn btn-secondary' ) ; newButton . innerHTML = currentQuestionInfo . choices [ i ] ; newChoice . appendChild ( newButton ) ; choicesContainer . appendChild ( newChoice ) ; } questionContainer . style . display = "block" ; }
This function loads a question and choices into our DOM
This function loads a question and choices into our DOM
// Empty the choices container // Initialize a variable to track how much time has elapsed since the user got the question // Set an interval to track the time elapsed //Load the next question // if currentQuestion is equal to the length of questions then the quiz is over // for each answer choice, do the following... // Create a div and set its class to 'choice' // Create a button and set its text content to the choice // Append the button to the choice div and append the choice div to the choicesContainer