closes #3 show correct answer to previous question

This commit is contained in:
Akbar Rahman 2021-06-05 12:11:00 +01:00
parent 155f41afc1
commit 1a3bb1f139
3 changed files with 14 additions and 0 deletions

View File

@ -10,6 +10,8 @@ const answerDHTML = document.getElementById("answer_d");
const bodyHTML = document.getElementsByTagName("body")[0]
const incorrectAnswersTable = document.getElementById('incorrectAnswersTable');
const correctAnswersTable = document.getElementById('correctAnswersTable');
const previousQuestionAnswer = document.getElementById('previousQuestionAnswer');
const previousQuestionText = document.getElementById('previousQuestionText');
const resultsHTML = document.getElementById("results");
const scoreHTML = document.getElementById("score");
const settingsHTML = document.getElementById("settings");
@ -127,6 +129,11 @@ function updateState() {
}
options[Math.floor(Math.random()*4)] = countries[newQuestion].capital;
if (state.question) state.previousQuestion = {
"question": state.question,
"options": state.options,
"answer": state.answer
};
state.question = newQuestion;
state.options = options;
state.answer = countries[newQuestion].capital;
@ -145,6 +152,10 @@ function updateScreen(){
answerCHTML.getElementsByClassName("text")[0].innerHTML = state.options[2];
answerDHTML.getElementsByClassName("text")[0].innerHTML = state.options[3];
questionHTML.innerHTML = `what is the capital of <span id="questionCountry">${state.question}</span>?`;
if (state.previousQuestion ) {
previousQuestionAnswer.innerHTML = state.previousQuestion.answer;
previousQuestionText.style.display = "";
}
}
function displayEndScreen() {

View File

@ -49,6 +49,8 @@
background: var(--good);
}
#previousQuestionAnswer { background: var(--green) }
#game .answer {
display: flex;
justify-content: space-evenly;

View File

@ -36,6 +36,7 @@
<p class="letter" id="d">d</p>
<p class="text">answer d text</p>
</div>
<p id="previousQuestionText" style="display: none"> answer to previous question: <span id="previousQuestionAnswer"> </span></p>
</div>
<div style="display: none" id="results">
<h1 id="resultsBreakdownHeader"> results breakdown </h1>