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

564
Views
Why is form.addEventListener not a function?

Followed a tutorial, still says "form.addEventListener is not a function" I've tried looking for the issue and still cant find it

const correctAnswers = ['B', 'B', 'B', 'B'];
const form = document.querySelector = ('.quiz-form');

form.addEventListener('submit', e => {
    e.preventDefault();

    let score = 0;

    const userAnswers = [form.q1.value, form.q2.value, form.q3.value, form.q4.value];

    //check answers
    userAnswers.forEach((answer, index) => {
        if(answer === correctAnswers[index]){
            score += 25;
        }
    });

    console.log(score);

});
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

It's because you are trying to call the .addEventListener on a string (".quiz-for" in this case). You should be calling it on an HTML element (form in your case).

Change:

const form = document.querySelector = ('.quiz-form');

to:

const form = document.querySelector('.quiz-form');

Let me know if you need any more explanation.

about 4 years ago · Juan Pablo Isaza Report

0

You are not doing querySelector properly

   const form = document.querySelector = ('.quiz-form');

should be changed to

   const form = document.querySelector('.quiz-form');
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!