Counting Cards - Think I'm almost there

I think I’m getting there it’s just one that’s not passing. Can anyone help me.
Many thanks!!

My code thus far

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 7:

case 8:

  case 9:

  count = 0;

break  ;



case 10:

case “J”:

case “Q”:

case “K”:

case “A”:

count-- ;

} if (count <= 0) {

return count + " Hold"

} else if (count > 0) {

return count + " Bet"

}

return “Change Me”;

// Only change code above this line

}

cc(2); cc(3); cc(7); cc(‘K’); cc(‘A’);

  **Your code so far**

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 7:
  case 8:
    case 9:
    count = 0;
  break  ;

  case 10:
case "J":
case "Q":
case "K":
case "A":
count-- ;




} if  (count <= 0) {
return count + " Hold"

} else if (count > 0) {
return count + " Bet"
}

return "Change Me";
// 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/95.0.4638.69 Safari/537.36

Challenge: Counting Cards

Link to the challenge:

This section in your switch statement will not function as intended:

break;
case 7:
  case 8:
    case 9:
    count = 0;
  break  ;

Not changing the count is not the same thing as zeroing it!
the cases where the count doesn’t change can simply be omitted as nothing changes.
Also, drop your final return statement if you’re not planning on using it.

1 Like

Got it!!! 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 7:

      case 8:

      case 9:

      break;

      case 10:

      case "J":

      case "Q":

      case "K":

      case "A":

      count--;

} if(count <=0){

return count + " Hold";

} else {

return count + " Bet";

}

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