Counting Cards What AM I doing wrong?

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:
   
    break;
    case 10:
    case "J":
    case "Q":
    case "K":
    case "A":
 
    break;
  }
  if (card>=2 && card<=6)
  {
     count++
  }
  else if (card==="J"||card==="Q"||card==="K"||card==="A")
  { 
     count--
  }
  else {
    return count + "Bet";
    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(7); cc('K'); cc('A');

Your browser information:

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

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

Why do you have there the switch statements and are not using it?

there is no action taken for any of the cases you have there

Only one of your if else statements is going to be executed, so you are returning something only when you have cards 7, 8, 9 or 10

Try explaining what your code do, piece by piece, and what your doubts are, you need to work a bit more on the logic of your code, what you want to get and how you want to obtain it and what your code actually does

Step 1: determine to which group your card belongs
Step 2: increment count accordingly

Count Change Cards
+1 2, 3, 4, 5, 6
0 7, 8, 9
-1 10, ‘J’, ‘Q’, ‘K’, ‘A’

Step 3: Return a string with the current count and the string Bet if the count is positive, or Hold if the count is zero or negative. The current count and the player’s decision ( Bet or Hold ) should be separated by a single space.


Stepping through this one: Cards Sequence 3, 2, A, 10, K should return -1 Hold

count is 0
card 3, in first group so increment count by 1, count is now 1 and 1 is positive so return “1 Bet”
card 2, in first group so increment count by 1, count is now 2 and 2 is positive so return “2 Bet”
card A, in last group so increment count by -1, count is now 1 and 1 is positive so return “1 Bet”
card 10, in last group so increment count by -1, count is now 0 and 0 is not positive so return “0 Hold”
card K, in last group so increment count by -1, count is now -1 and -1 in not positive so return “-1 Hold”


The first two steps could be solved using switch or with if…else but mixing the two is not doing what you think.
The last step (Bet or Hold) will involve a decision based on the current value of count.