Counting Cards.. What am I missing?

Hi everyone,

I’ve been working on this for the past hour and still can’t figure out what I’m missing. The answer seems to be write whenever I put in the cards but FCC keeps saying that there is an error

My code so far

var count = 0;

function cc(card) {
 switch(card) {
    case 2:
    case 3:
    case 4:
    case 5:
    case 6:
      return count++;
    case 7:
    case 8:
    case 9:
      return count = count;
    case 10:
    case 'J':
    case 'Q':
    case 'K':
    case 'A':
      return count--;

var holdBet = "Hold";
  if (count > 0) {
    holdBet = "Bet";

return count + " " + holdBet;

cc(2); cc(3); cc(4); cc(5); cc(6);


Your browser information:

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

Challenge: Counting Cards

Link to the challenge:

I also changed the output to “return count + holdBet;” and then added a space before the holdBet variable definition to make it " Hold" and " Bet" and still no dice…

Hey there,

have a look at this explanation how a switch works:

the output if your function is count++ or count = count or count--

a return statement stops a function, the if statement is never executed

Hi there thanks for sending this my way. Its a bit confusing because in the FCC lesson, the examples all have multiple breaks and return statements which is why I wrote my code the way I did… But the link you sent seems to suggest that switches shouldn’t be written this way.

hi so should I remove the return statements in the function so that the if statement can be executed? If I do that then how do I tell the function what to output based on the case?

You can put a second switch or an if/else below your first switch

awesome I just figured it out – thank you!

1 Like


Happy coding!