HOW TO MODIFY THIS SCRIPT AND PREVENT .test-box
elements from having same color as siblings provided that they are 4 .test-boxes
var colors = [
"rgb(100, 50, 100)",
"rgb(200, 100, 200)",
"rgb(150, 75, 150)",
"rgb(230, 80, 230)",
];
function colorsFunction() {
// Get all the elements that use the "view" class but do it using querySelectorAll
var divs = Array.prototype.slice.call(document.querySelectorAll(".test-box"));
// Loop through the array of divs
divs.forEach(function(div){
// Set the background color of each div
div.style.backgroundColor = colors[Math.floor(Math.random() * colors.length)];
});
}