As someone who is new to coding, I decided to create a basic color game using jQuery. The idea is simple - there are 4 options, you click the correct one, and an alert appears. I stored the answer along with some dummy colors in an array called "colors[]" and used that array to set the CSS for each color box.
var dummy = '#ccc';
var answer = '#ff9900';
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("Congratulations!");
}
However, I'm struggling to properly define the answer for the click function to work correctly. Any help would be greatly appreciated. Thank you.