Pls i need help with the counting cards game

Tell us what’s happening:
Describe your issue in detail here.

   **Your code so far**

let count = 0;

function cc(card) {
 // Only change code below this line
switch (card){
 case 2:
 case 3:
 case 4:
 case 5:
 case 6:
 return "5 Bet"
 break;

 case 7:
 case 8:
 case 9:
 return "0 Hold"
 break;


 case 10:
 case "J":
 case "Q":
 case "K":
 case "A":
 return "-5 Hold"
 break;

 case 3:
 case 7:
 case "Q":
 case 8:
 case "A":
 return "-1 Hold"
 break;

 case 2:
 case "J":
 case 9:
 case 2:
 case 7:
 return "1 Bet"
 break;

 case 2:
 case 2:
 case 10:
 return "1 Bet"
 break;

 case 3:
 case 2:
 case "A":
 case 10:
 case "K":
 return "-1 Hold"
}

 return "change me";
 // 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) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.110 Safari/537.36

Challenge: Counting Cards

Link to the challenge:

Hello there.

Do you have a question?

If so, please edit your post to include it in the Tell us what’s happening section.

Learning to describe problems is hard, but it is an important part of learning how to code.

Also, the more information you give us, the more likely we are to be able to help.

1 Like

Were you able to figure it out? :grinning:

1 Like

No not yet still greatly stuck :cry:

To start, it looks like you don’t quite understand how switches work.

Let’s start there. The switch should be based upon the value of the cards. What are all of the values of the cards? What should happen to count for each value?

1 Like

Hey, sorry to break it to you, but that switch-case is complete garbage. Like, it starts out kinda normal, but then it just goes on and on and on without following any logic I can make out.
Like, it contains several “case 2” for example. Where did you get that from? That can in no way work out…

Consider going back to the introduction of switch-case…

Also just for the record: This task has 2 seperate conditions to check. First the value of the card, then to “Bet” or “Hold”. You cannot do both in one go. You especially cannot hard-code some answers like “-1 Hold”. Your super especially cannot write a 30-line long switch-case with repeated cases as if you somehow try to hardcode different responses for consecutives calls - because the function doesn’t remember anything. Every time it’s called, it’s starting at the top.

If you have trouble with that, you might need to go back to the introduction of functions and better familiarize yourself with these concepts.

1 Like

Ohh OK thanks i will have to start from the top again… For better understanding I guess.

You can read through this freeCodeCamp article for better understanding

2 Likes

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.