I'm in the middle of a website project for a co-worker. My friend and code mentor helped me with a mobile menu using JS for the project. Using that function as a starting point, I tried changing the background color with an on-click event. With no success, I turned to Google and found a simple way to do what I wanted using
Then it was time to tackle the text color change on the h1 element. After some more Google, I found
document.getElementById().style.color to work nicely.
Everything was functional and I excitedly sent my friend the CodePen link, which at the time was the same code as this post's cover image- five nearly identical functions and all. It was gratifying to hear that it looked good, but he then said I could do the same thing with only one function. After all that work!?
Here is the single function background color changer. I hope you have as much fun as I do clicking those buttons. :)