I've recently developed a function that allows two different elements (randomColor1 and randomColor2) to select colors from an array. However, the issue arises occasionally where both elements end up picking the same color.
The value of both elements ends up being identical.
Below are my codes. Can someone guide me on how to modify them in order to ensure that both elements choose distinct colors each time? I am still learning JavaScript.
function GetValue() {
var myarray = new Array(" #ff0000 ", " #ffe100 ", " #95ff00 ", " #2c8d94 "," #911961 ");
var randomColor1 = myarray[Math.floor(Math.random() * myarray.length)];
var randomColor2 = myarray[Math.floor(Math.random() * myarray.length)];
document.getElementById(" message ").innerHTML = randomColor1 + randomColor2;
}