# Counting card functions

Hi there,
I am trying to create this function which will do the counting cards for Blackjack!
The criteria is:

‘count’ variable will be incremented if ‘card’ is between 2 and 6;
‘count’ will be incremented to 0 if ‘card’ is between 7 and 9; (nothing happens to count);
‘count’ will be decremented if ‘card’ is 10, J, Q, K, A.

Here is the code:

``````let count = 0;

function cc(card) {
if (card <= 6)
count++;
else if (card >="10")
count--;
return count + (count > 0 ? ' Bet' : ' Hold');
}

const result = cc(2); cc(3); cc(4); cc(2); cc(2);
console.log(result);
``````

Since my count was initialized to 0, should it return 4? Because all the numbers passed to card as a value was between 2 and 6;

No, it should return 5 but you made mistake when you assigned the result into function’s value.

``````const result = cc(2); cc(3); cc(4); cc(2); cc(2);
// this looks like

const result = cc(2);
cc(3);
cc(4);
cc(2);
cc(2);
// therefore result is equal to 1. but if you write
cc(2);
cc(3);
cc(4);
cc(2);

const result = cc(2);
// then the result variable is equal to 5
``````
1 Like