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);
});
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.
You are not doing querySelector properly
const form = document.querySelector = ('.quiz-form');
should be changed to
const form = document.querySelector('.quiz-form');