Card counting code does not work

Can somebody tell me what is wrong with my code?
after I run the code it shows I have a lot of mistakes. I do not see any.
Thank you.

let count = 0;

function cc(card) {
// Only change code below this line

switch (card)
{
  case 2:
  case 3:
  case 4:
  case 5:
  case 6:
  count++;
  break;
  case 10:
  case "J":
  case "Q":
  case "K":
  case "A":
  count --;
  break;
}
if (count > 0) 
{
  return count + "Bet"; 
}
else 
{ 
return count + "Hold"; 
} 
return count; 
// 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/99.0.4844.51 Safari/537.36

Challenge: Counting Cards

Link to the challenge:

If you add at the very bottom of the code console.log(cc()), what do you see?

You should see 0Hold - doesn’t that look just a little bit off?

I see the lines like this one: Cards Sequence 2, 3, 4, 5, 6 should return the string 5 Bet
But I do not see any mistakes in my code. What am I doing wrong?

Did you add a console.log statement like I said you should…?

Your output has a very small error that is easier to see if you log the output of your function.

Hey

i see two problem here, you already returning all of the possibilities but then you returning the count value again, and the second problem is space You must leave a space between the number and the string

1 Like

yes, I did, but nothing has changed. Maybe I added it in the wrong place.

Adding console.log statements doesn’t magically fix your code. You need to look at what is logged and make changes accordingly.

When I add the console.log statement, I see 0Hold - doesn’t that look just a little bit off?

It is great that you solved the challenge, but instead of posting your full working solution, it is best to stay focused on answering the original poster’s question(s) and help guide them with hints and suggestions to solve their own issues with the challenge.

We are trying to cut back on the number of spoiler solutions found on the forum and instead focus on helping other campers with their questions and definitely not posting full working solutions.

ur right sorry, should i delete?

I deleted the second returning value, still not working

that’s not the main problem, main problem is about your returned strings

nooooooo please do not))))))))

@pletniri, please look at your returned string.

Currently you are returning strings that look like 0Bet or -2Hold, but the instructions say

The current count and the player’s decision ( Bet or Hold ) should be separated by a single space.

Example Outputs: -3 Hold or 5 Bet

1 Like

I got it. After I added a space in the strings, it worked. Thanks a lot!

1 Like

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