views:

79

answers:

0

There are 8 cards on the table, with four faces visible and four hidden. Click on a card to turn it and if there's a pip-match or suit-match, show sparks around the associated cards.

Problem is, I'm either doing something wrong logic-wise, or .concat() is not working. Because some sparks show and some do not.

The whole game could probably be refactored into proper objects but that is beyond my current level (I've been learning JS for a month now). Framework used is RightJS. Posted the whole function for clarity's sake and a bit of context.

function pick(card){  
  var matches = [], pip = [], suit = [];

  //Check for matches
  ['card1', 'card2', 'card3', 'card4'].each(function(el){
    if (hand[el].charAt(0) == 'j') { matches.push(card); matches.push(el); } //Joker
    else if (hand[card].charAt(1) == hand[el].charAt(1) || hand[card].charAt(0) == 'j') { matches.push(card); pip.push(el); } //Pip match
    else if (hand[card].charAt(0) == hand[el].charAt(0) || hand[card].charAt(0) == 'j') { matches.push(card); suit.push(el); } //Suit match
  });
  if(pip.length > suit.length){ matches.concat(pip); } else { matches.concat(suit); }

  //Hide old bling
  $$('.bling').each(function(el){
    el.hide();
  });

  //Show bling
  if (matches.length > 0) {
    matches.each(function(el){
      $(el).firstChild.show();
    });
  }

  //Show the card from hand
  $(card).setClass(hand[card]);
  turned++;

  // New turn if all have been clicked
  if (turned == 4){
    turned = 0;
    newturn();
  }
}