I'm super new to coding and I was trying to make a simple color game using jQuery. To put it short, 4 options, click the right one, an alert pops out. I randomly put the answer in an array ( colors[] ) along with other dummies, and then use that array to put into css.
var dummy = '#aaa';
var answer = '#ee00aa';
var colors = [dummy,answer,dummy,dummy];
for (var i = 1; i <= 4; i++) {
$('#colorBox'+i).css('background', ''+colors[i-1]+'');
}
$('#colorBox'+i).click(function() {
if ($(this).css('background', ''+colors[answer]+'') == true) {
alert("Gratz!");
}
The problem is, I cant find a way to define the answer for this click function to work. Thanks.
$(this).css('background', ''+colors[answer]+'')You are setting the background color, not getting its value..css('background')