I'm having a problem using variables with Jquery, and i just can't figure out what the problem is. In this instance i am trying to insert a random class to my li. When i tried alerting color i can cleary see that it writes .green or .red. Following that logic i should be able to use the variable to add my class right? But it is not working. What am i doing wrong?
(function(){
$('li').on('click', function(){
var number = Math.floor(Math.random() * 2);
var colorA = ['.green', '.red'];
var color = colorA[number];
$(this).addClass(color);
});
})();