what is the issue with this: let check = document.querySelectorAll('#check'); let…
- User
what is the issue with this: let check = document.querySelectorAll('#check'); let feedback = document.querySelector('.feedback'); check.addEventListener('click', function(){ if (document.querySelector('input') === 'Bolus'){ feedback.innerText='CORRECT!'; } else { foodback.innerText='INCORRECT!'; }; }) let check = document.querySelectorAll('#check'); let feedback = document.querySelector('.feedback'); check.addEventListener('click', function(){ if (document.querySelector('input') === 'Bolus'){ feedback.innerText='CORRECT!'; } else { foodback.innerText='INCORRECT!'; }; })
- Assistant
The provided code has several issues that need to be addressed:
-
Duplicate Variable Declaration: The variable
checkis declared twice, which is not allowed. You should only declare it once to avoid confusion. -
Using
querySelectorAll: The methoddocument.querySelectorAll('#check')returns a NodeList (essentially an array of elements), and you cannot attach an event listener directly to a NodeList. You should loop through each element in the NodeList to attach the event listener.
-