# Counting card functions

**URL:** <https://forum.codewithmosh.com/t/counting-card-functions/18035>\
**Category:** JavaScript\
**Created:** [February 1, 2023, 11:00am UTC](https://forum.codewithmosh.com/t/counting-card-functions/18035 "2023-02-01T11:00:49Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![YuriAmancio](https://avatars.discourse-cdn.com/v4/letter/y/e47c2d/32.png) [@YuriAmancio](https://forum.codewithmosh.com/u/YuriAmancio)\
**Post date:** [February 1, 2023, 11:00am UTC](https://forum.codewithmosh.com/t/counting-card-functions/18035/1 "2023-02-01T11:00:49Z")

</div>

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:

```auto
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;

---

<div class="post-metadata">

**Author:** ![abdunozir](https://avatars.discourse-cdn.com/v4/letter/a/a9a28c/32.png) [@abdunozir](https://forum.codewithmosh.com/u/abdunozir)\
**Post date:** [February 1, 2023, 2:18pm UTC](https://forum.codewithmosh.com/t/counting-card-functions/18035/2 "2023-02-01T14:18:13Z")

</div>

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

```auto
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

```
