I'm not sure what the problem is, I'm following a YT tutorial and even the exact same code.
this shows in problem
script.js:37
Uncaught TypeError: Cannot set properties of null (setting 'innerText') at showQuestion (script.js:37:31) at setnextQuestion (script.js:33) at HTMLButtonElement.startGame (script.js:26:5) showQuestion @ script.js:37 setnextQuestion @ script.js:33 startGame @ script.js:26
This is my script code:
const startButton = document.getElementById('start-btn')
const nextButton = document.getElementById('next-btn')
const questionContainElement = document.getElementById('question-container')
const questionElement = document.getElementById('question')
const answerButtonsElement = document.getElementById('answer-buttons')
let shuffledQuestionIndex;
let quizScore = 0;
startButton.addEventListener('click', startGame)
nextButton.addEventListener('click ',() =>{
currectQuestionIndex++
setnextQuestion()
})
function startGame(){
startButton.classList.add('hide')
shuffledQuestionIndex=question.sort(() =>Math.random() -0.5)
currectQuestionIndex=0;
questionContainElement.classList.remove('hide')
setnextQuestion()
quizScore=0
}
function setnextQuestion(){
resetState();
showQuestion(shuffledQuestionIndex[currectQuestionIndex])
}
function showQuestion(question) {
questionElement.innerText = question.question;
question.answers.forEach((answer) =>{
const button =document.createElement('button')
button.innerText=answer.text;
button.classList.add('btn')
if(answer.correct)
{
button.dataset.correctanswer.correct
}
button.addEventListener('click', selectAnswer)
answerButtonsElement.appendChild(button)
})
}
Thankful for any kind of help