I'm trying to add a class to a random button, but .addClass()
is not working and shows me an error, and when I tried to use Vanilla JS classList.add()
everything is working fine.
const button = $('.btn');
const sound = $('.audio');
const wrongSound = $('.audio-wrong');
let randomNumber = Math.floor(Math.random() * 4);
button.on('click', () => {
startGame();
});
const startGame = () => {
console.log(button);
console.log(randomNumber);
button[randomNumber].toggleClass("pressed");
}
Vanilla JS is working, but jQuery shows me an error.