# Counting Cards Help?

**URL:** <https://forum.freecodecamp.org/t/counting-cards-help/165668>\
**Category:** General\
**Created:** [December 28, 2017, 5:18am UTC](https://forum.freecodecamp.org/t/counting-cards-help/165668 "2017-12-28T05:18:38Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![AKSD1411](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/aksd1411/32/70409_2.png) [@AKSD1411](https://forum.freecodecamp.org/u/AKSD1411)\
**Post date:** [December 28, 2017, 5:18am UTC](https://forum.freecodecamp.org/t/counting-cards-help/165668/1 "2017-12-28T05:18:38Z")

</div>

**Tell us what’s happening:**  
I tried this and it worked, to my surprise. Because I don’t understand why the if statement is not getting executed every time the switch runs?

**Your code so far**

```auto
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++;
      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 (Macintosh; Intel Mac OS X 10_13_2) 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:** ![kevcomedia](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/kevcomedia/32/125737_2.png) [@kevcomedia](https://forum.freecodecamp.org/u/kevcomedia)\
**Post date:** [December 28, 2017, 5:29am UTC](https://forum.freecodecamp.org/t/counting-cards-help/165668/2 "2017-12-28T05:29:38Z")

</div>

It’s actually working. The output that you see on the left is the output of the last call to the `cc` function. If you plugged each call in `console.log`, you can see the output of each call (not visible on the challenge page, but you can see it in your browser’s console).

I made a quick repl to demonstrate:  
https://repl.it/repls/BeigeOverdueDuck?lite=true

---

<div class="post-metadata">

**Author:** ![AKSD1411](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/aksd1411/32/70409_2.png) [@AKSD1411](https://forum.freecodecamp.org/u/AKSD1411)\
**Post date:** [December 28, 2017, 5:31am UTC](https://forum.freecodecamp.org/t/counting-cards-help/165668/3 "2017-12-28T05:31:26Z")

</div>

So it’s just not visible in the challenge page?

---

<div class="post-metadata">

**Author:** ![kevcomedia](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/kevcomedia/32/125737_2.png) [@kevcomedia](https://forum.freecodecamp.org/u/kevcomedia)\
**Post date:** [December 28, 2017, 5:35am UTC](https://forum.freecodecamp.org/t/counting-cards-help/165668/4 "2017-12-28T05:35:16Z")

</div>

Yeah. It’s also mentioned in a comment in the code. Testing your code in another environment (like repl.it) helps if you get stuck in a challenge and need to insert a couple of `console.log`s in the code to debug.

---

<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, 5:13pm UTC](https://forum.freecodecamp.org/t/counting-cards-help/165668/5 "2021-01-16T17:13:07Z")

</div>

Closed on January 16, 2021, 5:13pm UTC


