|
|
@@ -99,8 +99,7 @@ function answerClicked(event) { |
|
|
|
|
|
|
|
function checkAnswer(answer) { |
|
|
|
let questionIndex = question.getAttribute('data-index'); |
|
|
|
console.log(questions[questionIndex].correctAnswer); |
|
|
|
if (questions[questionIndex].correctAnswer == answer) { |
|
|
|
if (questions[questionIndex].correct_answer == answer) { |
|
|
|
resultContainer.children[questionIndex].classList.replace( |
|
|
|
'is-dark', |
|
|
|
'is-success' |
|
|
@@ -120,7 +119,7 @@ function addTotalScore() { |
|
|
|
|
|
|
|
function init() { |
|
|
|
question.setAttribute('data-index', 0); |
|
|
|
randomizeQuestions(); |
|
|
|
// randomizeQuestions(); |
|
|
|
setNewQuestion(); |
|
|
|
} |
|
|
|
|
|
|
@@ -128,15 +127,16 @@ function setNewQuestion() { |
|
|
|
index = question.getAttribute('data-index'); |
|
|
|
if (index === '10') { |
|
|
|
console.log('new game now'); |
|
|
|
question.innerText = `Your score was ${totalCorrect.innerText}, would you like to play again?`; |
|
|
|
question.innerHTML = `Your score was ${totalCorrect.innerText}, would you like to play again?`; |
|
|
|
gameOver = true; |
|
|
|
} else { |
|
|
|
question.innerText = questions[index].question; |
|
|
|
console.log(questions); |
|
|
|
question.innerHTML = questions[index].question; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
function resetGame() { |
|
|
|
init(); |
|
|
|
fetchFromAPI(); |
|
|
|
let resultArray = Array.from(resultContainer.children); |
|
|
|
resultArray.forEach(function(result) { |
|
|
|
result.classList.replace('is-danger', 'is-dark'); |
|
|
@@ -146,4 +146,19 @@ function resetGame() { |
|
|
|
totalCorrect.innerText = 0; |
|
|
|
} |
|
|
|
|
|
|
|
init(); |
|
|
|
function fetchFromAPI() { |
|
|
|
fetch( |
|
|
|
'https://opentdb.com/api.php?amount=10&category=15&difficulty=medium&type=boolean' |
|
|
|
) |
|
|
|
.then(response => { |
|
|
|
return response.json(); |
|
|
|
}) |
|
|
|
.then(myJson => { |
|
|
|
questions = myJson.results; |
|
|
|
}) |
|
|
|
.then(response => { |
|
|
|
init(); |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
fetchFromAPI(); |