Card Counting Problem

Tell us what’s happening:
My code was not working so i used the code in the hints and it still doesn’t work. What am I doing wrong?
the link is Learn Basic JavaScript: Counting Cards | freeCodeCamp.org

  **Your code so far**
       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";
}


  // Only change code above this line 


var 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";
}


// 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/92.0.4515.131 Safari/537.36 Edg/92.0.902.67

Challenge: Counting Cards

Link to the challenge:

What do the failing tests say? The thing that jumps out when I just look at your code without more information is that you don’t have any spaces in the string that you return.

2 Likes

The failing tests said that it should return 5 Bet etc. Thank you for yoyr time and I am sorry, I watched the video and I had to assign a variable holdbet. Now it works! Thank you!

You do not need to create an extra variable. You just need to make sure that the string you return is properly formatted.

1 Like

You are not returning “5 Bet”. You would be returning “5Bet”.

1 Like

Thank you for your time! I found the answer in the video. My fault I should have watched the video first!

There is nothing wrong with asking questions. Personally, I think learning how to ask questions about code is an important skill that is important to practice and get good at.

1 Like

That’s very true! Thank you again!

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