JavaScript: Card Count

It’s the little accomplishments without assistance that keep me moving forward. Today’s real challenge on Free Code Camp’s basic JavaScript segment was a simple card count that gave me the chance to practice switch/case and if/else logic:

var count = 0;

// increment/decrement count based on card 
function cc(card) {
  switch(card){
    case 2:
    case 3:
    case 4:
    case 5:
    case 6:
      count++;
      break;
    case 7:
    case 8:
    case 9:
      count = count;
      break;
    case 10:
    case "J":
    case "Q":
    case "K":
    case "A":
      count--;
      break;
  }
  
  // return count based on incrementation
  if(count > 0){
    return count + " Bet";
  }else{
    return count + " Hold";
  }
}

// test results
cc(2); cc(3); cc(7); cc('K'); cc('A');

This looks like a potential code pen project!

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s