Eu estou fazendo um sistema de Quiz, me ajudem pfvr
const question = document.querySelector('#question');
const choices = Array.from(document.querySelectorAll('.choice-text'));
const progressText = document.querySelector('#progressText');
const scoreText = document.querySelector('#score');
const progressBarFull = document.querySelector('#progressBarFull');
let currentQuestion = {}
let acceptingAnswers = true
let score = 0
let questionCounter = 0
let availableQuestions = []
let questions = [
{
question:'Quanto é 2 +2?',
choice1:'2',
choice2:'4',
choice3:'21',
choice4:'17',
answer: 2,
},
{
question:'O prédio mais alto do mundo está localizado em qual cidade?',
choice1:'Dubai',
choice2:'New York',
choice3:'Shangai',
choice4:'None of the above',
answer: 1,
},
{
question:'Qual a porcentagem de adultos americanos que acreditam que o leite com chocolate vem de vacas marrons?',
choice1:'20%',
choice2:'18%',
choice3:'7%',
choice4:'33%',
answer: 3,
},
{
question:'Aproximadamente que porcentagem das interrupções de energia nos Estados Unidos são causadas por esquilos?',
choice1:'10-20%',
choice2:'5-10%',
choice3:'15-20%',
choice4:'30-40%',
answer: 1,
},
]
const SCORE_POINTS = 100
const MAX_QUESTIONS = 4
startGame = () => {
questionCounter = 0
score = 0
availableQuestions = [...questions]
getNewQuestion()
}
getNewQuestion = () => {
if(availableQuestions.length === 0 || questionCounter > MAX_QUESTIONS) {
localStorage.setItem('mostRecentScore', score)
return window.location.assign('/end.html')
}
questionCounter++
progressText.innerText = `Question ${questionCounter} of ${MAX_QUESTIONS}` ( É AQUI QUE NÃO ESTÁ RECEBENDO )
progressBarFull.style.width = `${(questionCounter/MAX_QUESTIONS) * 100}%` ( É AQUI QUE NÃO ESTÁ RECEBENDO )
const questionsIndex = Math.floor(Math.random() * availableQuestions.length)
currentQuestion = availableQuestions[questionsIndex]
question.innerText = currentQuention.question
choices.forEach(choice =>{
const number =choice.dataset['number']
choice.innerText = currentQuestion['choice' + number]
})
availableQuestions.splice(questionsIndex, 1)
acceptingAnswers = true
}
choices.forEach(choice =>{
choice.addEventListener('click', e => {
if(!acceptingAnswers) return
acceptingAnswers = false
const selectedChoice = e.target
const selectedAnswer = selectedChoice.dataset['number']
let classToApply = selectedAnswer == currentQuestion.answer ? 'correct' :
'incorrect'
if(classToApply === 'correct') {
incrementScore(SCORE_POINTS)
}
selectedChoice.parentElement.classList.add(classToApply)
setTimeout(() => {
selectedChoice.parentElement.classList.remove(classToApply)
getNewQuestion()
}, 1000)
})
})
incrementScore = num => {
score += num
scoreText.innerText = score
}
startGame()