Aim: I am trying to make a candy crush game with buttons as candies. So it is needed that the buttons have random colors (among 4 - red/ green/ blue / yellow).
What I tried: I created 4 classes of colors in css -
.pink{
background-color: red;
}
.blue{
background-color: blue;
}
.green{
background-color: green;
}
.brown{
background-color: yellow;
}
And tried to assign these classes to the buttons randomly. But I am new to jQuery. I searched on the web and I tried the following script:
var colors = Array ('red','blue','green','yellow');
var candy = document.querySelectorAll("button");
for(var i=0;i<colors.length;i++){
candy[i].style.background-color=colors[i];
}
It is not working. What can I try to resolve it?