# Counting cards - Going over one number multiple times

I’m failing the counting card challenge because these two tests won’t pass:

1. 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');
``````

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?

Sorry, that is a good guess, but based on a spurious correlation.

``````if (count > 1) {
return count + " Bet";
}  else  {
return count + " Hold";
}
``````

Specifically the first line.

``````if (count > 1) {
``````

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.)

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.

Compare that to the logic in your `if` statement.

1 Like

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.

See this post to find the backtick on your keyboard.
Note: Backticks (`) are not single quotes (’).

1 Like

Thank you! I didn’t realize.

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

1 Like