0

what is happening in var newRgb = 'rgb(' + arr[0] + ',' + arr[1] + ',' + arr[2] + ')'; please help me to understand this.

function changeColor(){ var newColor = makeColor(); var box = document.getElementById('box').style.backgroundColor = newColor; document.getElementById('rgb').innerHTML = newColor; } function makeColor(){ var arr = []; for(var i = 0; i < 3; i++){ var num = Math.floor(Math.random() * 256); arr.push(num); } var newRgb = 'rgb(' + arr[0] + ',' + arr[1] + ',' + arr[2] + ')'; return newRgb; }

10th Jul 2018, 11:44 AM
Nayem
1 Respuesta
+ 2
this creates a random RGB color by making an array with 3 random values that can represent a color
10th Jul 2018, 12:00 PM
hinanawi
hinanawi - avatar