Counting Cards - What am I doing wrong here?

I honestly can’t figure out what I am doing wrong???

I gave up and looked at the solution code and honenstly… I still don’t see the issue with what I wrote??? Can anybody tell me what I’ve missed???

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

cc(2); cc(3); cc(7); cc('K'); cc('A');

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:74.0) Gecko/20100101 Firefox/74.0.

Challenge: Counting Cards

Link to the challenge:

A few things:

  • Remember that as soon as a return statement is hit, the function is done. Any code after a return statement is “unreachable”. Your if/else block for “Bet” and “Hold” will never run.
  • This return statement (and the third one) will return the result of the assignment. It will not return the value of count.
1 Like