¿Alguien puede decirme por qué esto no funciona? la intención es cambiar el título cuando se hace clic en un color rgb aleatorio (la función onclick ni siquiera aparece en mi página de git: https://lucaspaulii.github.io/portfolio/ )
const title = document.getElementById("title"); let randNum = () => { let num = Math.floor(Math.random() * 255); return num } let randColor = () => { return 'rgb('+ randNum() + ',' + randNum() + ',' + randNum() + ')' } let newColor = randColor(); title.addEventListener('click', function onClick() { title.style.color = newColor; })está llamando a randColor solo una vez, llámelo dentro del controlador:
const title = document.getElementById("title"); let randNum = () => { let num = Math.floor(Math.random() * 255); return num } let randColor = () => { return 'rgb('+ randNum() + ',' + randNum() + ',' + randNum() + ')' } title.addEventListener('click', function onClick() { title.style.color = randColor(); }) <div id="title">click here</div>