Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

196
Views
Can I write a function that checks if an answer pressed by a user clicked is true or false and load the new question once it is done?

I am trying to create a simple online quiz game using HTML, CSS and JavaScript. My current issue is that I am trying to write a function that checks if the answer the used clicked is true or false and load the new question once it is done. Is there something I am missing from my code here?

function selectAnswer(e) {
    console.log("I'm here!")
    const selectedButton = e.target;
    const correct = selectedButton.dataset.correct;
    checkAnswers(document.newButton, correct)
    Array.from(answerButtonsElement.children).forEach(newButton => {
      checkAnswers(newButton, newButton.dataset.correct)
    })
    if (shuffledQuestions.length > currentQuestionIndex + 1) {
      submitButtonElement.classList.remove('hide')
    } else {
      startButton.innerText = 'Restart'
      startButton.classList.remove('hide')
    }
  

}

function checkAnswers(element, correct) {
    resetPage
    if (correct === true) {
        element.classList.add('correct-btn');
    } else {
        element.classList.add('incorrect-btn');
    }
}


function resetPage(element) {
    element.classList.remove('correct-btn')
    element.classList.remove('incorrect-btn')

}
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

in the Function "checkAnswers" you are calling the function "resetPage" without giving any variable and without also parenthesis.

in this function:


function checkAnswers(element, correct) {
    resetPage(element)
    if (correct === true) {
        element.classList.add('correct-btn');
    } else {
        element.classList.add('incorrect-btn');
    }
}
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!