I would like the user to change the font style of a header with each button click. Right now it only works once. Can someone please help. Do I use a while loop? If/else? Sorry noob here that needs some help. Thanks in advance.
const text = document.querySelector('h1');
const randomFontButton = document.getElementById('randomFontButton');
randomFontButton.addEventListener('click', () => {
let fontType = [ "Arial", "Verdana", "Helvetica","Times New Roman",
"Times", "serif"];
let rand = fontType[Math.floor(Math.random()*fontType.length)];
text.style.fontFamily = fontType[rand];
});
Aucun commentaire:
Enregistrer un commentaire