I'm trying to loop over an array that contains three variables with a forEach loop, and change the value of each variable to a random number between 0-255.
I've started out by giving each variable a simple value:
let rgb1 = 1;
let rgb2 = 2;
let rgb3 = 3;
And then I've put those variables into an Array:
let rgbVariables = [rgb1,rgb2,rgb3];
I have my function that returns a random number between 0-255
function randomColor() {
return Math.floor((Math.random() * 255));
}
And lastly my function that loops over the array
function refreshRGBNumbers() {
rgbVariables.forEach(function(rgb) {
rgb = randomColor();
});
The refreshRGBNumbers function is called when I click a button. I have verified that the function is being called correctly, but when I check the value of the variables in the array they remain 1,2,3.
What do I need to do here to get the function to correctly replace the array variables with the random number?