Counting Cards I can't see what it is I did wrong?

Tell us what’s happening:

What am I missing?

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++;
        break;
   case 10:
   case "J":
   case "Q":
   case "K":
   case "A":
      return count--;
      break;
 }
 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(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/75.0.3770.100 Safari/537.36.

Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/basic-javascript/counting-cards

In your switch statement, you are returning either count++ or count--. Basically your function returns something and ends before ever making it into the if else statement. I believe, what you want the switch statement to do is just increment/decrement count and then move on, leaving any return strictly to the ending if else statement.

got it, ty. I don’t know why I put a return statement there. I always struggle with that, when or if I need a return statement. I’m just struggling to really grasp this whole javascript. I don’t want to give up but I feel like I forget what I just learned right after I did it. Mental block I guess…

You want to use a return statement if you want to immediately exit the current function and return a value back to where the function was called.