Counting Cards problem driving me crazy

Counting Cards problem driving me crazy
0

what the hell is the problem here!!!

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++;
     return count + " Bet";
     break;
    case 7:
    case 8:
    case 9:
     return count + " Hold";
     break;
    case 10:
    case 'J':
    case 'Q':
    case 'K':
    case 'A':
     count--;
     return count + " Hold";
     break;
  }
  
  return "Change Me";
  // 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');

Context is very important, specify what is the problem that you’re having so you can be helped properly

What you return should be based on the value of count. You are currently determining it based on the value of card.

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

here’s the link

1 Like

i dont understand…

now i understand i shouldnt have used return in switch but in a separate line with an if statement but i dont understand why?

There is nothing inherently wrong with having a return in a switch, but the logic of this one is wrong. Whether you return “Bet” or “Hold” should be based on what the value of count is. Your code returns “Bet” if card is less than 7, no matter what count is. It returns “Hold” if card is more than 6, no matter what count is.

2 Likes

ohhh now i get it.its pretty simple actually.thanksssssssssssssss