I set out to create a simple spin wheel exercise, but it quickly became more challenging than I anticipated. After researching how to make one online, I found code similar to mine that worked on a JSFiddle Example, yet my own code still didn't work.
Feeling frustrated, I decided to delete everything and simply copy and paste the code from the working JSFiddle example. To my surprise, it still did not work. You can view the JSFiddle here.
I even added an alert to test if the function was being triggered, but it wasn't. The code appeared fine, and it worked in the JSFiddle environment.
var img = document.querySelector('img');
img.addEventListener('click', onClick, false);
function onClick() {
alert('ALERT ME');
this.removeAttribute('style');
var deg = 500 + Math.round(Math.random() * 500);
var css = 'transform: rotate(' + deg + 'deg);';
this.setAttribute('style', css);
}
If some parts are unclear, I apologize as I tend to overcomplicate things at times.