Counting Cards - help

Hi everyone,

I’ve done what I thought would be correct, using switch. It is not working.
Any advice?
Thanks :slight_smile:

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
}

// Add/remove calls to test your function.
// Note: Only the last will display
cc(2); cc(3); cc(7); cc('K'); cc('A');[spoiler]This text will be blurred[/spoiler]

Your count logic is correct, but your return values are not. You are returning values like “5Bet” and “-2Hold” instead of “5 Bet” and “-2 Hold”.

1 Like

That worked, so I needed a space between the quotes for the return values.
I’m trying to read up why that space is needed.
Do you know the reason for why the return values don’t work without the space?

Thanks!

Because the last line of the instructions states the following:

The current count and the player’s decision ( Bet or Hold ) should be separated by a single space.

1 Like

Ah right! I gotta read the details more.
Thanks again!

It’s all about the details.

1 Like

please how did you put the space