Variable value not saving

let generateButton = document.querySelector('.cta')
let colorBox = document.querySelector('.color-box')

let r = ''
let g = ''
let b = ''

const generateNumber = () => {
  return Math.floor(Math.random() * 256)
}

const generateColor = () => {
  r = generateNumber()
}


colorBox.style.backgroundColor = "lightblue";

generateButton.addEventListener('click', () => {
  generateButton.textContent = `RGB(${r},${g},${b})`
})

I am trying to use generate color to change the value of variable a to a random value generated by the generateNumber fuction, but the variable value won’t change? Any help?

You never call the generateColor function and it also only sets one of the variables.

Not really sure what you are trying to do here either. Setting the textContent of the button doesn’t have anything to do with generating a color.

You’re right I forgot to call it, that’s on me, thanks for the info, I’ll try more to see if it works. It’s supposed to be a color generator fyi. Thanks again mate

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.