Dynamic background with CSS? How to make?

1

I have a question, is it possible to change background according to a condition?

Example:

function A() {
  if (meuArray.length === 7) {
    eu quero background verde
  } else {
    background azul
  }
}

At first I'm doing a card game called Black Jack or 21 in Brazil, and so far I have not found a viable form of background or a CSS in the array that contains the values of each card.

Would anyone have a tip or how to do it? Thanks

    
asked by anonymous 07.06.2018 / 04:59

1 answer

1

Good afternoon you can use the numbers of the cards and mount an array with them and when you use them just call the position of the array.

example:

var cartas = [];
cartas[0] = '#f333dd';
cartas[1] = '#ffffff';
cartas[2] = '#000000';
cartas[3] = '#f23f5d';

....

$(element).attr('style','background-color:' + cartas[2] + '');

I hope this code helps you.

    
07.06.2018 / 16:00