Undefined Error

Here is my code.

/*eslint-env es6*/
const button = document.querySelector('button')
const body = document.querySelector('body')
const colors = getRandomColor()

body.style.backgroundColor = 'violet'
button.addEventListener('click', changeBackground)

function changeBackground(){
const colorIndex= parseInt(Math.random(colors.length))
body.style.backgroundColor = colors[colorIndex]

I keep getting the message of ERROR: ‘getRandomColor’ is not defined. [no-undef]. I’m not sure what this means? I thought I defined it by setting the const. Maybe it just isn’t working with my code? Any ideas?

Hello @throwaway ,

Do you have a getRandomColor() function defined anywhere?

I get a similar error:

With the function defined:


thank you, it worked but I want it to change the background to a random color on click, and now it doesn’t change the colors… any help?