Skip to content

Commit

Permalink
Update GameHandeler.js
Browse files Browse the repository at this point in the history
  • Loading branch information
JoelBerglund05 authored Dec 11, 2024
1 parent e17545e commit 5042d66
Showing 1 changed file with 3 additions and 23 deletions.
26 changes: 3 additions & 23 deletions js/GameHandeler.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,15 @@ export default class GameHandeler {
sessionStorage.getItem("questionsAnswerd") || 0,
);

console.log("Before rendering - questionsAnswerd:", this.questionsAnswerd);
console.log("Total questions in JSON:", json.questions.length);

// Get the existing template content or create new if not exists

let questionHtml = this.gameContainer.querySelector(".question-vh");
if (!questionHtml) {
const template = document.getElementById("answer-form");
questionHtml = template.content.cloneNode(true).firstElementChild;
this.gameContainer.appendChild(questionHtml);
}

// Update the content directly in the existing elements

const question = questionHtml.querySelector("#question");
const answersBtn = [
questionHtml.querySelector("#btn-1"),
Expand All @@ -50,20 +47,12 @@ export default class GameHandeler {
json.questions[this.questionsAnswerd].answer4,
];

// Update question text

question.textContent = json.questions[this.questionsAnswerd].question;

// Update answer buttons
for (let i = 0; i < 4; i++) {
answersBtn[i].textContent = answer[answersLeftToPlace[i]];
}

// Log to verify
console.log(
"Updated question:",
json.questions[this.questionsAnswerd].question,
"questions answerd: ", this.questionsAnswerd,
);
}

CreatePointsScreen() {
Expand All @@ -82,8 +71,6 @@ export default class GameHandeler {

pointsSetter.textContent = sessionStorage.getItem("points");

console.log(pointsHtml);

sessionStorage.setItem("questionsAnswerd", 0);
sessionStorage.setItem("points", 0);

Expand All @@ -96,13 +83,6 @@ export default class GameHandeler {
sessionStorage.getItem("questionsAnswerd") || 0,
);

console.log("Current question index:", this.questionsAnswerd);
console.log("Total questions:", json.questions.length);
console.log("Submitted answer:", answer);
console.log("Correct answer:", json.questions[this.questionsAnswerd].answer1);

console.log(json, "oihqawidj", answer);

if (json.questions[this.questionsAnswerd].answer1 == answer) {
this.points = sessionStorage.getItem("points");
this.points++;
Expand Down

0 comments on commit 5042d66

Please sign in to comment.