Help post for JavaScript counting cards

Tell us what’s happening:

Your code so far

var count = 0;

function cc(card) {
// Only change code below this line
   switch (card) {
     case 2:
     case 3:
     case 4:
     case 5:
     case 6:
      return count++;
    case 10:
    case "J":
    case "Q":
    case "K":
    case "A":
      return 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
console.log(cc(2)); console.log(cc(3)); console.log(cc(4)); console.log(cc(5)); console.log(cc(6));

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.87 Safari/537.36.

Challenge: Counting Cards

Link to the challenge:

In your switch statement, you are returning count++ or count--. Remember when you return a variable, you exit out of the function. You’re supposed to return count when you get to the end of the function and check whether or not you should bet or hold. Since count is a global variable, running count++ will alter it.

1 Like

Thanks for your solution.
It works