Card Counting Switch Confusion

So, I encountered a really confusing issue while trying to solve this. The solution for the switch approach looks like this:
switch (card) {
case 2:
case 3:
case 4:
case 5:
case 6:
count++;
break;

That’s fine, but, while looking through the hints and other peoples’ solutions, I saw someone formatting their switch like this:

switch (card) {
case 2,3,4,5,6:
count++;
break;

This is where my problem is; When using this person’s format, I found that count would never increase. However, formatting cases 10, J, Q, K, and A the same way would decrease count properly (I tested this in Chrome’s console). Could anyone explain this one to me? Is there an issue with laying out cases horizontally?

A case only matches against one value or condition. This should not work.

1 Like

That would explain why case 2,3,4,5,6: would never actually add to the count. But, doing the same thing for case 10, ‘J’, ‘Q’, ‘K’, ‘A’: actually worked (count-- would work). That’s what had me stumped for quite a while.

That should also not work.

Then I’m even more confused than before. xD Well, I’m past it already, but I wanted to try and get some understanding on how that actually worked (or didn’t work in this case). Appreciate the quick response.

In each case, the condition is strictly compared, so

switch (card) {
  case 1, 2, 3:
  ...
}

is the same as

if (card === 1, 2, 3) {
  ...
}

and that is not a valid comparison.

with all the cards? it will with only one of them