How do you not count 7, 8, or 9 in the counting cards exercise and why do you use count as a variable (instead of card)?

How do you not count 7, 8, or 9 in the counting cards exercise and why do you use count as a variable (instead of card)?


Continuing the discussion from freeCodeCamp Challenge Guide: Counting Cards:

{ switch(card) {case 1:
  case 2:
  case 3:
  case 4:
  case 5:
  case 6:
   case 7:
   case 8:
   case 9:
      card = '';
    case 10:
    case 'J':
    case 'Q':
    case 'K':
    case 'A':
      card = -1;
  if (card > 0) {return "bet";} 
  else {return "hold";}     
  return card;               }

I assume this is what is holding me back. I’m trying to avoid looking at the answer, but had to for the count part… and now I want to understand the logic of this

By the way, this method of asking why has helped me with solving novel problems independently, so I greatly appreciate the help.


Also, why is one able not to use break between each case in this example? I noticed the example does not have break between each case.

 case 9:
      card = '';

What is going on here? Why are you setting the argument (card) to an empty string? Similarly, are you sure that you are supposed to set card to negative one for J, Q, K, and A.

Every block where you have

case <something>:

You are setting your case statement to do nothing for those values. break means to break out of the switch statement entirely. Your switch statement does not perform any operations for the values 2, 3, 4, 5, 7, and 8.

I also believe that you need to look more carefully at what you are supposed to return.

Having seen a few of your in-progress solutions, I’d like to offer some general advice when it comes to your approach:

  1. Read the instructions very carefully. Read the instructions several times. Break them down and make sure you know exactly what the expected results should be.
  2. Work on your solutions in small steps. Start with the most basic requirements or the simplest case from the instructions and focus on getting that right. Then build off of that.


I feel incredibly bad for asking when I do, but sometimes I don’t understand the questions. This has occured less over time, but especially when I was learning what a switch was (how I should think about it so that I respond to situations where a switch would be useful correctly, I mean), I had trouble making an action plan and responding to a novel situation. Would you suggest writing a “to do” list:

I am asked I have done
x x
y y
z z



The formatting is horrible here, but I hope you get what I mean. two columns essentially.


I have actually solved some of the questions while I was critically thinking about it before a moderator has given me advice about what to do. But I will keep your advice in mind.


counting cards Nov 30

Example of my critical thinking.


Never feel bad about asking! I certainly wasn’t trying to shame you for that.


Look at my code^)

var count = 0;
function cc(card) {
if (card>1 && card<7)
else if (card>6 && card<10)
else if (card == 10 || card == ‘J’ || card == ‘Q’ || card == ‘K’ || card == ‘A’)
if (count>0)
{return count + " Bet"; }
else if (count<=0)
{return count + " Hold";}
else {
return “Change Me”;}


hi owen, how much different is my code from yours:

function cc(card) {
  // Only change code below this line
    if(card>=2 &&card<=6){
        return count + "Bet";
    else if(card>=7 && card <=9){
        return count + "Hold";
    else if(card==10||card=='J'||card=='Q'||card=='K'||card=='A'){
        return count + "Hold"; 
  else return "Change Me";
  // Only change code above this line


my code doesn’t run at all…


I’ve edited your post for readability. When you enter a code block into the forum, precede it with a line of three backticks and follow it with a line of three backticks to make easier to read. See this post to find the backtick on your keyboard. The “preformatted text” tool in the editor (</>) will also add backticks around text.


Your code runs, but it returns the wrong answer in all the test cases.

The biggest problem you have is that you need to separate the logic which increases and decreases the value of count from the logic which actually returns the applicable string.

Currently, you are correctly increasing and decreasing the count variable based on the card values, but then your return statements are inside the same if statements concerning the card values.

Note: The card values in any given call to the function do not directly determine what gets returned. Only the current value of count determines what gets returned.

Lastly, make sure the string you return includes the count plus a space character and then the word Hold or Bet. Currently you have no space between the count value and the string “Hold” or “Bet” which will causes test failures.


Wow, thanks a lot randel, I really appreciate it.


hi randel, sorry I am back again but I am still not passing…not sure what I am still doing wrong, my code below:

  // Only change code below this line
    if(card >= 2 && card <= 6)
   else if(card >= 7 && card <= 9)
      {count = count;}
    else if (card==10 || card=='J' || card=='Q' || card=='K' || card=='A')

    if (count > 0)
    {return count + " Bet";}

    else if (count <= 0);
    {return count + " Hold";}

  else return "Change Me";
  // Only change code above this line


omg the rogue semi-colon was all that was stopping the program from doing what I expected it to do…