|
|
@@ -45,17 +45,12 @@ const questions = [ |
|
|
|
}, |
|
|
|
]; |
|
|
|
|
|
|
|
const state = { |
|
|
|
turn:0, |
|
|
|
numberCorrect:0, |
|
|
|
questions:[], |
|
|
|
let shuffledQuestions; |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
const correctAnswerCount = document.getElementById('total-correct'); |
|
|
|
const question = document.getElementById('question'); |
|
|
|
const falseBtn = document.getElementById('answer-false'); |
|
|
|
const trueBtn = document.getElementById('answer-true'); |
|
|
|
const $questionsContainer = document.getElementById('result-container'); |
|
|
|
const $correctAnswerCount = document.getElementById('total-correct'); |
|
|
|
const $questionContainer = document.getElementById('question'); |
|
|
|
const $btnContainer = document.getElementById('answer-container'); |
|
|
|
|
|
|
|
function shuffleQuestions(questions) { |
|
|
|
let tempQuestions = questions.slice(); |
|
|
@@ -65,88 +60,77 @@ function shuffleQuestions(questions) { |
|
|
|
shuffledQuestions.push(tempQuestions.splice(index, 1)[0]); |
|
|
|
} |
|
|
|
return shuffledQuestions; |
|
|
|
}; |
|
|
|
|
|
|
|
function trueFalseClick() { |
|
|
|
showQuestions(); |
|
|
|
const resultTag = document |
|
|
|
.getElementById('result-container') |
|
|
|
.getElementsByTagName('div'); |
|
|
|
questionCounter++; |
|
|
|
console.log(teller); |
|
|
|
const arrayAnswer = questions[questionCounter].correctAnswer; |
|
|
|
console.log(arrayAnswer); |
|
|
|
|
|
|
|
if (this.innerHTML === 'False') { |
|
|
|
if (this.innerHTML === arrayAnswer) { |
|
|
|
correcteAntwoordenTeller(); |
|
|
|
resultTag[teller - 1].setAttribute( |
|
|
|
'class', |
|
|
|
'result tag is-success is-large' |
|
|
|
); |
|
|
|
} else { |
|
|
|
resultTag[teller - 1].setAttribute( |
|
|
|
'class', |
|
|
|
'result tag is-danger is-large' |
|
|
|
); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if (this.innerHTML === 'True') { |
|
|
|
if (this.innerHTML === arrayAnswer) { |
|
|
|
correcteAntwoordenTeller(); |
|
|
|
resultTag[teller - 1].setAttribute( |
|
|
|
'class', |
|
|
|
'result tag is-success is-large' |
|
|
|
); |
|
|
|
} else { |
|
|
|
resultTag[teller - 1].setAttribute( |
|
|
|
'class', |
|
|
|
'result tag is-danger is-large' |
|
|
|
); |
|
|
|
} |
|
|
|
function renderQuestion(currentIndex) { |
|
|
|
if (currentIndex === 10) { |
|
|
|
const score = $correctAnswerCount.innerText; |
|
|
|
$questionContainer.innerHTML = `Your score is ${score}, play again?`; |
|
|
|
} else { |
|
|
|
$questionContainer.innerHTML = shuffledQuestions[currentIndex].question; |
|
|
|
} |
|
|
|
$questionContainer.dataset.index = currentIndex; |
|
|
|
} |
|
|
|
|
|
|
|
function showQuestions() { |
|
|
|
if (teller === 9) { |
|
|
|
console.log('win-conditie'); //win-conditie maken |
|
|
|
question = correcteAntwoorden.innerHTML; |
|
|
|
document |
|
|
|
.getElementById('answer-true') |
|
|
|
.addEventListener('click', buttonRestart); |
|
|
|
function renderCorrectCount(reset) { |
|
|
|
if (reset) { |
|
|
|
$correctAnswerCount.innerText = 0; |
|
|
|
} else { |
|
|
|
teller++; |
|
|
|
let arrayQuestion = questions[teller].question; |
|
|
|
question.innerHTML = arrayQuestion; |
|
|
|
$correctAnswerCount.innerText = |
|
|
|
parseInt($correctAnswerCount.innerText) + 1; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
function correcteAntwoordenTeller() { |
|
|
|
count++; |
|
|
|
correcteAntwoorden.innerHTML = count; |
|
|
|
function renderQuestionState($currentQuestion, state) { |
|
|
|
switch (state) { |
|
|
|
case 'success': |
|
|
|
$currentQuestion.classList.add('is-success'); |
|
|
|
break; |
|
|
|
case 'danger': |
|
|
|
$currentQuestion.classList.add('is-danger'); |
|
|
|
break; |
|
|
|
default: |
|
|
|
$currentQuestion.classList.remove('is-success', 'is-danger'); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
function buttonRestart() { |
|
|
|
count = 1; |
|
|
|
teller = 0; |
|
|
|
questionCounter = -1; |
|
|
|
init(questions); |
|
|
|
} |
|
|
|
function answerClicked(event) { |
|
|
|
if (event.target.matches('.answer')) { |
|
|
|
const currentIndex = parseInt($questionContainer.dataset.index); |
|
|
|
const selectedAnswer = event.target.matches('#answer-true'); |
|
|
|
const $currentQuestion = $questionsContainer.children[currentIndex]; |
|
|
|
|
|
|
|
if (currentIndex === 10) { |
|
|
|
if (selectedAnswer) { |
|
|
|
init(); |
|
|
|
} |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
function renderQuestionState(currentQuestion, state) { |
|
|
|
if(state === "correct") { |
|
|
|
currentQuestion.classList.add('is-success'); |
|
|
|
if ( |
|
|
|
(shuffledQuestions[currentIndex].correctAnswer === 'True') === |
|
|
|
selectedAnswer |
|
|
|
) { |
|
|
|
renderQuestionState($currentQuestion, 'success'); |
|
|
|
renderCorrectCount(); |
|
|
|
} else { |
|
|
|
renderQuestionState($currentQuestion, 'danger'); |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
renderQuestion(currentIndex + 1); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
function init() { |
|
|
|
state.questions = shuffleQuestions(questions); |
|
|
|
state.turn = 0; |
|
|
|
state.numberCorrect = 0; |
|
|
|
shuffledQuestions = shuffleQuestions(questions); |
|
|
|
|
|
|
|
Array.from($questionsContainer.children).forEach(function($question) { |
|
|
|
renderQuestionState($question); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
renderQuestion(0); |
|
|
|
renderCorrectCount(true); |
|
|
|
} |
|
|
|
|
|
|
|
init(); |
|
|
|
$btnContainer.addEventListener('click', answerClicked); |