# Counting Cards plz explain

**URL:** <https://forum.freecodecamp.org/t/counting-cards-plz-explain/228944>\
**Category:** Curriculum Help\
**Tags:** javascript\
**Created:** [September 22, 2018, 8:36am UTC](https://forum.freecodecamp.org/t/counting-cards-plz-explain/228944 "2018-09-22T08:36:36Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![sanji](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/sanji/32/159525_2.png) [@sanji](https://forum.freecodecamp.org/u/sanji)\
**Post date:** [September 22, 2018, 8:36am UTC](https://forum.freecodecamp.org/t/counting-cards-plz-explain/228944/1 "2018-09-22T08:36:37Z")

</div>

**Tell us what’s happening:**

**Your code so far**

```js

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:**

User Agent is: `Mozilla/5.0 (Windows NT 10.0; WOW64; rv:62.0) Gecko/20100101 Firefox/62.0`.

**Link to the challenge:**

> **[freeCodeCamp.org](https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/basic-javascript/counting-cards)**
>
> Learn to Code — For Free

---

<div class="post-metadata">

**Author:** ![SpadeX](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/spadex/32/214293_2.png) [@SpadeX](https://forum.freecodecamp.org/u/SpadeX)\
**Post date:** [September 22, 2018, 9:14am UTC](https://forum.freecodecamp.org/t/counting-cards-plz-explain/228944/2 "2018-09-22T09:14:05Z")

</div>

Hey sanji, It’s really simple Look at switch case and it table as mention it will definitely get details.

| Count Change | Cards |
| --- | --- |
| +1 | 2, 3, 4, 5, 6 |
| 0 | 7, 8, 9 |
| -1 | 10, ‘J’, ‘Q’, ‘K’, ‘A’ |

---

<div class="post-metadata">

**Author:** ![sanji](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/sanji/32/159525_2.png) [@sanji](https://forum.freecodecamp.org/u/sanji)\
**Post date:** [September 22, 2018, 9:19am UTC](https://forum.freecodecamp.org/t/counting-cards-plz-explain/228944/3 "2018-09-22T09:19:33Z")

</div>

it didn’t pass the test , it saying output for  
cc(2) should be 5 Bet  
???

---

<div class="post-metadata">

**Author:** ![collinstommy](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/collinstommy/32/4996_2.png) [@collinstommy](https://forum.freecodecamp.org/u/collinstommy)\
**Post date:** [September 22, 2018, 11:08am UTC](https://forum.freecodecamp.org/t/counting-cards-plz-explain/228944/4 "2018-09-22T11:08:05Z")

</div>

In this case you need to see what your output is so you can see what is the difference between the expected and actual. `console.log` here is useful. Try changing your code to this so you can view your results:

```auto
  let result = "";
  if (count > 0)
    { 
      result = count +"Bet";
    }
    else
    {
      result = count +"Hold";
    }
    console.log(result);
    return result;

```

Hint: **space**

---

<div class="post-metadata">

**Author:** ![SpadeX](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/spadex/32/214293_2.png) [@SpadeX](https://forum.freecodecamp.org/u/SpadeX)\
**Post date:** [September 22, 2018, 1:28pm UTC](https://forum.freecodecamp.org/t/counting-cards-plz-explain/228944/5 "2018-09-22T13:28:39Z")

</div>

Look at the @collinstommy Post

Whenever you stuck then try to do the test your code . you get the solution and also improve the testing and debugging skills.

Hope this help you … … … …👨‍💻

---

<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:** [February 2, 2021, 11:29am UTC](https://forum.freecodecamp.org/t/counting-cards-plz-explain/228944/6 "2021-02-02T11:29:49Z")

</div>

Closed on February 2, 2021, 11:29am UTC


