Counting Cards assistance

Counting Cards assistance
0

#1

Tell us what’s happening:

Your code so far

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 '5 Bet';
      break;
    case 7:
    case 8:
    case 9:
      count += 0;
      return '0 Hold';
      break;
    case 3:
    case 7:
    case 'Q':
    case 8:
    case 'A':
      count --;
      return '-1 Hold';
      break;
    case 10:
    case 'J':
    case 'Q':
    case 'K':
    case 'A':
      count = count - 5;
      return '-5 Hold';
      break;
    case 2:
    case 'J':
    case 9:
    case 2:
    case 7:
      count = count + 1;
      return '1 Bet';
      break;
    case 2:
    case 2:
    case 10:
      count = count + 1;
      return '1 Bet';
     break;
    case 3:
    case 2:
    case 'A':
    case 10:
    case 'K':
      count = count -1;
      return '-1 Hold';
  } 
  
  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');

Your browser information:

Your Browser User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:56.0) Gecko/20100101 Firefox/56.0.

Link to the challenge:


#2

not sure why this is not working it runs ’ 1 hold’.


#3

You should not be hard coding the return values. Your function should calculate the value of count based on the value of card and then return a string with the count and a space character and then either “Hold” or “Bet” depending on the value of count.


#4

Furthermore, when you have a switch statement with multiple instance of the same case such as in:

var card = 2;

switch(card){
  case 2:
    console.log('first')
    break;
  case 2:
    console.log('second');
    break;
} 

The above code will only look at the first case:2 and ignore any case:2 which follows, which is why it would display 'first" to the console.