# Counting Cards (error on cards 7, 8, 9)

Tell us what’s happening:
Hey tribe
I’m only getting error messages coming up for cards 7, 8 and 9.

Truly grateful
xo

``````
var count = 0;

function cc(card) {
// Only change code below this line
if (card <= 6) {
count ++ ;
} else if (card == 10 || 'J' || 'Q' || 'K' || 'A') {
count -- ;
}

if (count <= 0) {
return count + " Hold";
} return count + " Bet";
}

// Only change code above this line

// Note: Only the last will display
cc(2); cc(3); cc(7); cc('K'); cc('A');
``````

User Agent is: `Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:63.0) Gecko/20100101 Firefox/63.0`.

Sup tribe memeber @pinealfriend.

The first thing I noticed is that you are missing a if condition for the 0 hold. That seems like a actual string you are supposed to return such as `if....return "0 hold"`. The rest? is for you to discover

Ah another tip, might be better to fully write each condition out, that way you 100% certain that one condition might not be playing with another, also keep a sharp eye on the flow of the logic.

Enjoy!

This is not correct

`else if (card == 10 || 'J' || 'Q' || 'K' || 'A')`

You need to check the card against the letters like you are with the number

`else if (card == 10 || card == 'J' ...etc)`

If my if statement (as above) includes ’ <= ’ symbol, should that not include the conditions for the 0 hold? Because it includes equal to 0?

Or do you mean that I need to specify adding zero for cards 7, 8 & 9? I am just not sure why I need to add a condition for these cards if the count is not changing as a result.

Thanks for helping me clarify

Thanks @lasjorg !

What surprised me is that I did not get any error messages for those cards (J, Q, K & A). Only received error messages for 7, 8 & 9. Could you please help me understand why that is? Why is it reading my code which is incorrect (as you generously pointed out above) and not returning an error on those cards?

edit: really appreciate your advice in helping gain a deeper understanding of what is going on!

lol! I thought that was another js feature! I thought “wow, you can chain ifs like that?” I guess not but js does not surprise me really

Sorry, I didn’t get back to you, it was really late for me. I’m not sure I understand the question, you should have been failing 3 tests, not 1, was that not the case?

Anyway, what happens with the if statement you had is type coercion. The strings are coerced to true, because of how JavaScript works they are considered a truthy value.

``````if(test === 10 || true) {
...
}
``````

Another example:

``````const test = 1;

if(test === 10 || 'somestring') {
console.log('true'); // logs out true
} else {
console.log('false');
}
``````

This is also sort of related to the “trick” used to give default values. Because we have default function parameters now, it is a little less used.

Example:

``````function printName (name) {
// If name is undefined it is a falsey value, so the string is used