{"size": 2756, "ext": "js", "max_stars_repo_path": "script.js", "max_stars_repo_name": "carvasquez206/A4-CodeQuiz", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "script.js", "max_issues_repo_name": "carvasquez206/A4-CodeQuiz", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "script.js", "max_forks_repo_name": "carvasquez206/A4-CodeQuiz", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 23.9652173913, "max_line_length": 95, "alphanum_fraction": 0.62808418}
/*timer to 10 minutes*/
var count = 180;
var interval = setInterval(function(){
  document.getElementById('count').innerHTML=count;
  count--;
  if (count === 0){
    clearInterval(interval);
    document.getElementById('count').innerHTML='Done';
    // or...
    alert("Sorry! You're out of time!");
  }
}, 1000);

/* Quiz questions/info */   
const quizData = [
{
    question: "Did Soulja Boy discover America?",
    a: "Drake stole his whole flow too",
    b: "Big Facts!",
    c: "Turned its Swag on",
    d: "All the above",
    correct: "d",
},
{
    question: "What does HTML stand for?",
    a: "Hypertext Markup Language",
    b: "Cascading Style Sheet",
    c: "Helicopters Terminals Motorboats Lamborginis",
    d: "JSon Object Notation",
    correct: "a",
},
{
    question: "Where is the correct place to insert a JavaScript tag?",
    a: "the Body section",
    b: "the Head section",
    c: "Mississippi",
    d: "Mike Jones",
    correct: "a"
},
{
    question: "Inside which HTML element do we put the JavaScript?",
    a: "Js",
    b: "JavaScript",
    c: "script",
    d: "scripting",
    correct: "c",
},


];

/* setting the const variables */
const quiz = document.getElementById('quiz')
const answerEls = document.querySelectorAll('.answer');

const questionEl = document.getElementById('question');
const a_text = document.getElementById('a_text');
const b_text = document.getElementById('b_text');
const c_text = document.getElementById('c_text');
const d_text = document.getElementById('d_text');   
const submitBtn = document.getElementById('submit');

let currentQuiz = 0;
let score = 0;


loadQuiz();
function loadQuiz() {

    deselectAnswers();
const currentQuizData = quizData[currentQuiz];
    questionEl.innerText = currentQuizData.question;
    a_text.innerText = currentQuizData.a;
    b_text.innerText = currentQuizData.b;
    c_text.innerText = currentQuizData.c;
    d_text.innerText = currentQuizData.d;
}

function getSelected() {
    let answer = undefined;
answerEls.forEach((answerEl) => {
        if (answerEl.checked) {
        answer = answerEl.id;
        }
    });
return answer;
}

function deselectAnswers() {
answerEls.forEach((answerEl) => {
        answerEl.checked = false;
});
}

submitBtn.addEventListener("click", () => {
    const answer = getSelected();
if (answer) {
        if (answer === quizData[currentQuiz].correct) {
        score++

    }

        currentQuiz++
    if (currentQuiz < quizData.length) {
            loadQuiz();
    } else {
            quiz.innerHTML = `
            <h2>You answered correctly at ${score}/${quizData.length} questions correctly.</h2>
                
                <button onclick="location.reload()">Reload</button>
            `;
        }
    }
});
