Changed around line 1
+ document.addEventListener('DOMContentLoaded', () => {
+ const questions = [
+ {
+ question: "Name something people do before going to bed.",
+ answers: [
+ { text: "Brush teeth", points: 45 },
+ { text: "Read book", points: 25 },
+ { text: "Set alarm", points: 15 },
+ { text: "Change clothes", points: 10 },
+ { text: "Check phone", points: 5 }
+ ]
+ },
+ {
+ question: "Name a favorite pizza topping.",
+ answers: [
+ { text: "Pepperoni", points: 40 },
+ { text: "Cheese", points: 30 },
+ { text: "Mushrooms", points: 15 },
+ { text: "Sausage", points: 10 },
+ { text: "Olives", points: 5 }
+ ]
+ }
+ // Add more questions here
+ ];
+
+ let currentQuestion = 0;
+ let score = 0;
+ let strikes = 0;
+ let foundAnswers = new Set();
+
+ const gameElements = {
+ score: document.getElementById('score'),
+ questionText: document.getElementById('current-question'),
+ answerInput: document.getElementById('answer-input'),
+ submitButton: document.getElementById('submit-answer'),
+ newGameButton: document.getElementById('new-game'),
+ nextQuestionButton: document.getElementById('next-question'),
+ answersLeft: document.getElementById('answers-left'),
+ strikeElements: document.querySelectorAll('.strike'),
+ answerSlots: document.querySelectorAll('.answer')
+ };
+
+ function initializeGame() {
+ currentQuestion = 0;
+ score = 0;
+ strikes = 0;
+ foundAnswers.clear();
+ updateUI();
+ loadQuestion();
+ }
+
+ function loadQuestion() {
+ const question = questions[currentQuestion];
+ gameElements.questionText.textContent = question.question;
+ gameElements.answersLeft.textContent = question.answers.length;
+ resetAnswerSlots();
+ foundAnswers.clear();
+ strikes = 0;
+ updateStrikes();
+ }
+
+ function resetAnswerSlots() {
+ gameElements.answerSlots.forEach(slot => {
+ slot.classList.add('hidden');
+ });
+ }
+
+ function updateUI() {
+ gameElements.score.textContent = score;
+ gameElements.nextQuestionButton.disabled = foundAnswers.size !== questions[currentQuestion].answers.length;
+ gameElements.answerInput.value = '';
+ gameElements.answersLeft.textContent = questions[currentQuestion].answers.length - foundAnswers.size;
+ }
+
+ function updateStrikes() {
+ gameElements.strikeElements.forEach((strike, index) => {
+ strike.classList.toggle('active', index < strikes);
+ });
+ }
+
+ function checkAnswer(input) {
+ const currentAnswers = questions[currentQuestion].answers;
+ const normalizedInput = input.toLowerCase().trim();
+
+ for (let i = 0; i < currentAnswers.length; i++) {
+ const answer = currentAnswers[i];
+ if (answer.text.toLowerCase() === normalizedInput && !foundAnswers.has(i)) {
+ foundAnswers.add(i);
+ score += answer.points;
+ gameElements.answerSlots[i].classList.remove('hidden');
+ updateUI();
+ return true;
+ }
+ }
+ return false;
+ }
+
+ gameElements.submitButton.addEventListener('click', () => {
+ const input = gameElements.answerInput.value;
+ if (input.trim() === '') return;
+
+ if (!checkAnswer(input)) {
+ strikes++;
+ updateStrikes();
+ if (strikes >= 3) {
+ alert('Game Over! Three strikes!');
+ initializeGame();
+ }
+ }
+ gameElements.answerInput.value = '';
+ gameElements.answerInput.focus();
+ });
+
+ gameElements.answerInput.addEventListener('keypress', (e) => {
+ if (e.key === 'Enter') {
+ gameElements.submitButton.click();
+ }
+ });
+
+ gameElements.newGameButton.addEventListener('click', initializeGame);
+
+ gameElements.nextQuestionButton.addEventListener('click', () => {
+ currentQuestion = (currentQuestion + 1) % questions.length;
+ loadQuestion();
+ updateUI();
+ });
+
+ initializeGame();
+ });