I’m failing the counting card challenge because these two tests won’t pass:
Cards Sequence 2, J, 9, 2, 7 should return 1 Bet and 2) Cards Sequence 2, 2, 10 should return 1 Bet.
My assumption is that it’s because these tests have a number (2) twice in the sequence and my code isn’t capable of going over the function twice? Does anyone know how I can fix this? Code:
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 += 1;
break;
case 7:
case 8:
case 9:
count += 0;
break;
case 10:
case 'J':
case 'Q':
case 'K':
case 'A':
count -= 1;
break;
}
if (count > 1) {
return count + " Bet";
} else {
return count + " Hold";
}
return (count+" "+decision);
// Only change code above this line
}
cc(2); cc(3); cc(7); cc('K'); cc('A');
Is that exactly the logic you want? Think really hard about this. I was able to add one character and get this to pass. (Or you could change a different character.)
Reread the instruction carefully:
The function will then return a string with the current count and the string Bet if the count is positive, or Hold if the count is zero or negative.
I’ve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.
You can also use the “preformatted text” tool in the editor (</>) to add backticks around text.
Ohhhhhkay, I thought when I was putting (count > 1) I was talking about the number on the card instead of the actual count haha but thank you for pointing it out! I passed it now