Other forum threads on the card counting challenge were really helpful, I feel like I got to a good understanding of how to arrive at my solution, but it doesn’t seem to give the correct outputs for all the examples given.
Here is my solution:
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 += 1;
break;
case 7:
case 8:
case 9:
count += 0;
break;
case 10:
case 'J':
case 'Q':
case 'K':
case 'A':
count -= 1;
}
if (count > 0) {
return count + " Bet";
}
return count + " Hold";
// Only change code above this line
}
console.log(cc(10, 'J', 'Q', 'K', 'A'));
cc(2); cc(3); cc(7); cc('K'); cc('A');
This solution is currently passing the lesson. However…
In the example I’ve tried to log, the lesson says “Cards Sequence 10, J, Q, K, A should return the string -5 Hold
”, but my log displays “-1 Hold” instead. In fact, none of the negative count values (10, J, Q, K, A) submitted seem to be returning values below -1, which makes me think something is either wrong with the way I’m testing it in the console or with the function count -= 1?