# Count Cards Solution Alternatives

Hello,
I’ve solved the count card test with the option of cases and using if/else.

``````var count = 0;

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

if (card < 7) {
count ++;
}
else if (card == 10 || card == "J" || card == "Q" || card == "K" || card == "A"){
count --;
}
else;

if (count > 0) {
return count+" Bet";
}
else
return count+" Hold";
// Only change code above 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
}

``````
``````
Which one is preferable and why??``````

If you want to post spoilers you should write the `[spoiler][/spoiler]` tags outside the backticks

Anyway, I have seen a long discussion about performance and such, but at the end the “correct” solution is the one you find easier to read or the one that is conventional for the team you work in.

1 Like