card counting example from fcc

here is a solved version of the card counting function from free code camp you can test it using console log.

Javascript

var count = 0;

function cc(card) {
  // Only change code below this line
  
  var return_val = "";

  switch(card) {
    case 2:
    case 3:
    case 4:
    case 5:
    case 6:
      count++;
      break;
    case 10:
    case "J":
    case "Q":
    case "K":
    case "A":
      count--;
  }

  if(count > 0) {
    return count + " Bet";
  } else {
    return count + " Hold";
  }

  // Only change code above this line
}

// Add/remove calls to test your function.
// Note: Only the last will display
cc(2); cc(3); cc(7); cc('K'); cc('A');

console.log( cc('K') );

Demo

External Link for card counting example from fcc

Other Items in javascript
Page Views

This page has been viewed 58 times.

Search Code
Search Code by entering your search text above.
Welcome

This is my test area for webdev. I keep a collection of code snippits here, mostly for my reference. Also if i find a good site, i usually add it here.

❤👩‍💻🕹