0

Here is my code:

window.addEventListener('keydown', randomD(e) {
   if (e.keyCode === 32);   
});


 function randomD(e) {
 const wordList = ['Carvedilol', 'Histrelin', 'Kadcyla', 'Mavyret', 'Paracetamol',     
 'Raloxifene', 'Saxagliptin'];
 const display = document.querySelector("#wordDisplay");
 const random = Math.floor(Math.random() * wordList.length);
 const ranWord = wordList[random];
 display.innerHTML = ranWord;
 }

I want the key to be spacebar. It says after the if argument that "e" is declared but its value is never read. I'm a beginner and am not sure how to fix this or what the error indicates exactly. Any help would be appreciated.

robH
  • 29
  • 1
  • You are not defining the listener properly. Either reference the already existing function by using just the name - `randomD` - or write the function body inside an anonymous inline function when calling `addEventListener`. You're trying to do both, which is invalid syntax. – CertainPerformance Aug 29 '22 at 23:48
  • Thank you that set me on the right path I appreciate your help. – robH Aug 30 '22 at 00:30

0 Answers0