Here is my code. The problem is that it generates one math.random value and that's it. I need it to keep generating value after each time I click a div
.
var rand = Math.random();
$(document).ready(function() {
if(rand < .5) {
$('div').click(function() {
$(this).addClass('blue');
});
} else if(rand < .7) {
$('div').click(function() {
$(this).toggleClass('red');
});
} else if(rand < .9) {
$('div').click(function() {
$(this).toggleClass('purple');
});
} else {
$('div').click(function() {
$(this).toggleClass('black');
});
}
});