Card Counting help (not the solution but a nudge in the right direction please) [SOLVED]

I’ve been at this for several hours; and I’m stuck.
https://gist.github.com/danthecardman/90a75d16b79b8278dc5a3761ff53bad3.js

In my code I passed 3 of the 7 requirements. What I’m not grasping is how to code up a switch statement for when a specific card sequence is required to pass the exercise.

Here are the requirements (the first 3 I coded properly):
Cards Sequence 2, 3, 4, 5, 6 should return "5 Bet"
Cards Sequence 7, 8, 9 should return "0 Hold"
Cards Sequence 10, J, Q, K, A should return "-5 Hold"
Cards Sequence 3, 7, Q, 8, A should return "-1 Hold"
Cards Sequence 2, J, 9, 2, 7 should return "1 Bet"
Cards Sequence 2, 2, 10 should return "1 Bet"
Cards Sequence 3, 2, A, 10, K should return “-1 Hold”

var count = 0;

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

  
  switch(card){
    case 2:
    case 3:
    case 4:
    case 5:
    case 6:
      card= "5 Bet";
      count +=1;
      break;
    case 7:
    case 8:
    case 9:
      card="0 Hold";
//      count +=1;
      break;
    case 10:
    case 'J':
    case 'Q':
    case 'K':
    case 'A':
      card="-5 Hold";
      count -=1;
      break;
      
   // case 3,7,'Q',8,'A':
    case 3:
    case 7:
    case 'Q':
    case 8:
    case 'A':
      card= "-1 Hold";
      count -=1;
      break;
   // case 2,'J',9,2,7:
    case 2:
    case 'J':
    case 9:
    case 2:
    case 7:
      card= "1 Bet"; 
      count +=1;
      break;
    //case 2,2,10:
    case 2:
    case 2:
    case 10:
      card= "1 Bet";
      count +=1;
      break;
    //case 3,2,'A',10,'K':
    case 3:
    case 2:
    case 'A':
    case 10:
    case 'K':
      card= "-1 Hold";
      count -=1;
     break;
  }
  
  return card;//"Change Me";
  // Only change code above this line
}

// Add/remove calls to test your function.
// Note: Only the last will display
//cc(3); cc(7); cc('Q'); cc(8); cc('A');
cc(2); cc('J'); cc(9); cc(2); cc(7);



gist:90a75d16b79b8278dc5a3761ff53bad3

Why are you adjusting card in your switch statement? Your first 3 appear to be correct, they’re not really as card simply holds the value this challenge expects as it met the case in the switch statement.

The extra cases after // case 3,7,‘Q’,8,‘A’ are not needed & I’m not quite sure what they’re meant to be about.

It’d be easier to evaluate the value of count after all arguments have been passed with an if statement & then return count + a string to say to hold or bet. Say if count is greater than 0, you’d like to return count + a string

1 Like

thank you @coles303 your suggestion helped me look at it completely different. I finally got it working