// UPDATES
const question = document.getElementById('query');
const choiceOne = document.getElementById('option1');
const choiceTwo = document.getElementById('option2');
const choiceThree = document.getElementById('option3');
const choiceFour = document.getElementById('option4');
const choiceFive = document.getElementById('option5');
// QUESTION SET
const questionsList = [
{
query: "Arrange these countries by total population",
options: [
{ "correct_order": 5, "details": "Ireland" },
{ "correct_order": 2, "details": "United States" },
{ "correct_order": 3, "details": "Russia" },
{ "correct_order": 1, "details": "China" },
{ "correct_order": 4, "details": "United Kingdom" }
]
},
{
query: "Sort these countries by size",
options: [
{ "correct_order": 2, "details": "Canada" },
{ "correct_order": 5, "details": "Ireland" },
{ "correct_order": 3, "details": "Australia" },
{ "correct_order": 4, "details": "Mexico" },
{ "correct_order": 1, "details": "Russia" }
]
},
{
query: "Rank these languages by number of speakers",
options: [
{ "correct_order": 2, "details": "English" },
{ "correct_order": 5, "details": "Arabic" },
{ "correct_order": 3, "details": "Hindustani" },
{ "correct_order": 4, "details": "Spanish" },
{ "correct_order": 1, "details": "Mandarin Chinese" }
]
}
]
// CREATE QUIZ FUNCTION
document.getElementById("initiate-quiz").onclick = generateQuiz;
let index = 0;
function generateQuiz() {
document.getElementById("prompt").classList.add("d-none");
document.getElementById("exam").classList.remove("d-none");
question.innerHTML = questionsList[index].query;
choiceOne.innerHTML = questionsList[index].options[0].details;
choiceTwo.innerHTML = questionsList[index].options[1].details;
choiceThree.innerHTML = questionsList[index].options[2].details;
choiceFour.innerHTML = questionsList[index].options[3].details;
choiceFive.innerHTML = questionsList[index].options[4].details;
};
// ALTER OPTIONS FUNCTION
let optionContainers = {
container1: choiceOneContainer,
container2: choiceTwoContainer,
container3: choiceThreeContainer,
container4: choiceFourContainer,
container5: choiceFiveContainer
}
function switchOptionsContainer(toggleButton, box1, box2) {
document.getElementById(toggleButton).addEventListener('click', () => {
$("#" + box1).children(":first").slideToggle('fast');
$("#" + box2).children(":first").slideToggle('fast', function () {
optionContainers[box2].appendChild(optionContainers[box1].firstElementChild);
optionContainers[box1].appendChild(optionContainers[box2].firstElementChild);
});
$("#" + box1).children(":first").slideToggle('fast');
$("#" + box2).children(":first").slideToggle('fast');
});
}
switchOptionsContainer("toggle1", "container1", "container2");
switchOptionsContainer("toggle2", "container2", "container3");
switchOptionsContainer("toggle3", "container3", "container4");
switchOptionsContainer("toggle4", "container4", "container5");
// VERIFY ANSWER FUNCTION
document.getElementById("confirmSelection").onclick = validateAnswer;
function validateAnswer() {
document.getElementById("confirmSelection").classList.add("d-none");
document.getElementById("nextQuery").classList.remove("d-none");
let points = 0;
if (choiceOneContainer.firstElementChild["correct_order"] === "1") {
document.getElementById("container1").classList.add("green-border")
} else {
document.getElementById("container1").classList.add("red-border")
}
};
// GO TO NEXT QUESTION FUNCTION
document.getElementById("nextQuery").onclick = nextQuestionButton;
function nextQuestionButton() {
if (index >= questionsList.length) {
index = 0;
return;
}
index++;
generateQuiz();
document.getElementById("nextQuery").classList.add("d-none");
document.getElementById("confirmSelection").classList.remove("d-none");
};
<div id="exam" class="questionnaire-box d-none">
<div id="query" class="quizzical-inquiry"></div>
<div id="container1" class="option-holder">
<div id="option1" class="selection"></div>
</div>
<div class="button-zone">
<button id="toggle1" class="btn-pattern"><i class="fas fa-sync exchange-trigger"></i></button>
</div>
<div id="container2" class="option-holder">
<div id="option2" class="selection"></div>
</div>
<div class="button-zone">
<button id="toggle2" class="btn-pattern"><i class="fas fa-sync exchange-trigger"></i></button>
</div>
<div id="container3" class="option-holder">
<div id="option3" class="selection"></div>
</div>
<div class="button-zone">
<button id="toggle3" class="btn-pattern"><i class="fas fa-sync exchange-trigger"></i></button>
</div>
<div id="container4" class="option-holder">
<div id="option4" class="selection"></div>
</div>
<div class="button-zone">
<button id="toggle4" class="btn-pattern"><i class="fas fa-sync exchange-trigger"></i></button>
</div>
<div id="container5" class="option-holder">
<div id="option5" class="selection"></div>
</div>
<button id="confirmSelection" class="submit-button btn btn-primary btn-lg">Verify Answer</button>
<button id="nextQuery" class="submit-button btn btn-primary btn-lg d-none">Next Question</button>
<button id="initiate-quiz" class="submit-button btn btn-primary btn-lg d-none">Start Quiz</button>
</div>