Counting Cards test didn't pass

Hello, I wonder why only 2nd and 5th test has passed, I’m stuck and don’t know what should I change in my code:

heres my code

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+=1;
    case 10:
    case "J":
    case "Q":
    case "K":
    case "A":
      return count-=1;
      }
  if (count <= 0) {
    return count + " Hold";
  }
  else {
    return count + " Bet";
  }
  // Only change code above this line
}

// Add/remove calls to test your function.
// Note: Only the last will display
cc(10); cc("J"); cc("Q"); cc("K"); cc("A");

I cleaned up your code.
You need to use triple backticks to post code to the forum.
See this post for details.

Your switch statement is returning the value of count so your code is only correct for the values that are not checked in the switch statement (7, 8, 9).

2 Likes

I’ve changed the
"return count += 1"
to
"count +=1;
break;"
and now it works. What’s the difference between these 2 ways?

A return always ends function execution.

1 Like