# Counting Cards JS Challenge

**URL:** <https://forum.freecodecamp.org/t/counting-cards-js-challenge/166456>\
**Category:** General\
**Created:** [January 2, 2018, 5:58pm UTC](https://forum.freecodecamp.org/t/counting-cards-js-challenge/166456 "2018-01-02T17:58:42Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![MtnLionBrian](https://avatars.discourse-cdn.com/v4/letter/m/c6cbf5/32.png) [@MtnLionBrian](https://forum.freecodecamp.org/u/MtnLionBrian)\
**Post date:** [January 2, 2018, 5:58pm UTC](https://forum.freecodecamp.org/t/counting-cards-js-challenge/166456/1 "2018-01-02T17:58:42Z")

</div>

**Tell us what’s happening:**

Hi, can someone tell me why this isn’t working? it looks good to me but maybe i’m overlooking something.

**Your code so far**

```auto

function cc(card) {
  var count = 0;
  switch(card){
    case 2:
    case 3:
    case 4:
    case 5:
    case 6:
      count++;
      break;
    case 10:
    case "J":
    case "Q":
    case "K":
    case "A":
      count--;
      break;
  }
  if (count > 0) {
    return count + " Bet";
  }
  else {
    return count + " Hold";
  }
  
  // Only change code above this line
}

// Add/remove calls to test your function.
// Note: Only the last will display
cc(2); cc(3); cc(7); cc('K'); cc('A');

```

**Your browser information:**

Your Browser User Agent is: `Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.84 Safari/537.36`.

**Link to the challenge:**  
[https://www.freecodecamp.org/challenges/counting-cards](https://www.freecodecamp.org/challenges/counting-cards)

---

<div class="post-metadata">

**Author:** ![ArielLeslie](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/arielleslie/32/264841_2.png) [@ArielLeslie](https://forum.freecodecamp.org/u/ArielLeslie)\
**Post date:** [January 2, 2018, 6:02pm UTC](https://forum.freecodecamp.org/t/counting-cards-js-challenge/166456/2 "2018-01-02T18:02:26Z")

</div>

You should not be resetting `count` to `0` every time that the function executes. In this case the solution is expected to use a global variable.

---

<div class="post-metadata">

**Author:** ![ILM](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/ilm/32/363239_2.png) [@ILM](https://forum.freecodecamp.org/u/ILM)\
**Post date:** [January 16, 2021, 6:35pm UTC](https://forum.freecodecamp.org/t/counting-cards-js-challenge/166456/3 "2021-01-16T18:35:48Z")

</div>


