# Undefined Error

**URL:** <https://discourse.processing.org/t/undefined-error/36023>\
**Category:** Beginners\
**Created:** [March 30, 2022, 11:32am UTC](https://discourse.processing.org/t/undefined-error/36023 "2022-03-30T11:32:12Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![throwaway](https://avatars.discourse-cdn.com/v4/letter/t/f475e1/32.png) [@throwaway](https://discourse.processing.org/u/throwaway)\
**Post date:** [March 30, 2022, 11:32am UTC](https://discourse.processing.org/t/undefined-error/36023/1 "2022-03-30T11:32:12Z")

</div>

Here is my code.

```auto
/*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?

---

<div class="post-metadata">

**Author:** ![glv](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/glv/32/18785_2.png) [@glv](https://discourse.processing.org/u/glv)\
**Post date:** [March 30, 2022, 2:39pm UTC](https://discourse.processing.org/t/undefined-error/36023/2 "2022-03-30T14:39:57Z")

</div>

Hello @throwaway ,

Do you have a _getRandomColor()_ function defined anywhere?

I get a similar error:

 ![image](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/3X/0/0/00ea743f0a30155ad3e1d4b17eae042150cd3a7a.png)

With the function defined:

 ![image](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/3X/6/a/6aa13fed20d144548c956f20db1026ab9b9177de.png)

`:)`

---

<div class="post-metadata">

**Author:** ![throwaway](https://avatars.discourse-cdn.com/v4/letter/t/f475e1/32.png) [@throwaway](https://discourse.processing.org/u/throwaway)\
**Post date:** [March 30, 2022, 3:22pm UTC](https://discourse.processing.org/t/undefined-error/36023/3 "2022-03-30T15:22:14Z")

</div>

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?
