# Counting Cards challenge, javascript doubt

**URL:** <https://forum.freecodecamp.org/t/counting-cards-challenge-javascript-doubt/141382>\
**Category:** General\
**Created:** [August 12, 2017, 6:24pm UTC](https://forum.freecodecamp.org/t/counting-cards-challenge-javascript-doubt/141382 "2017-08-12T18:24:00Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Didimoykds](https://avatars.discourse-cdn.com/v4/letter/d/7feea3/32.png) [@Didimoykds](https://forum.freecodecamp.org/u/Didimoykds)\
**Post date:** [August 12, 2017, 6:24pm UTC](https://forum.freecodecamp.org/t/counting-cards-challenge-javascript-doubt/141382/1 "2017-08-12T18:24:00Z")

</div>

Challenge : [freeCodeCamp Challenge Guide: Counting Cards](https://forum.freecodecamp.org/t/freecodecamp-challenge-guide-counting-cards/16809/48)  
Hello everyone, i’m still trying to figure out why on this code:

```
// Note: Only the last will display
cc(7); cc(8); cc(9); cc('K'); cc('A');

```

why only the last value is going to show.  
Someone can help me? 😁

---

<div class="post-metadata">

**Author:** ![rainythunderstorm](https://avatars.discourse-cdn.com/v4/letter/r/8797f3/32.png) [@rainythunderstorm](https://forum.freecodecamp.org/u/rainythunderstorm)\
**Post date:** [August 12, 2017, 6:35pm UTC](https://forum.freecodecamp.org/t/counting-cards-challenge-javascript-doubt/141382/2 "2017-08-12T18:35:38Z")

</div>

Try running it somewhere else. I think that its because the freecodecamp people did something behind the scenes. I wouldn’t wory about it too much.

You should ask this question as a seperate thread, because I’ve noticed that it  
applies to many exercises, and you probably won’t get that many people who know the reason in this one.

---

<div class="post-metadata">

**Author:** ![Didimoykds](https://avatars.discourse-cdn.com/v4/letter/d/7feea3/32.png) [@Didimoykds](https://forum.freecodecamp.org/u/Didimoykds)\
**Post date:** [August 12, 2017, 6:41pm UTC](https://forum.freecodecamp.org/t/counting-cards-challenge-javascript-doubt/141382/3 "2017-08-12T18:41:15Z")

</div>

Well, i wrote using “document.write()”, and it showed everything, yep they did something, thanks for helping!  
I thought that my logic was broken. 😅

---

<div class="post-metadata">

**Author:** ![mittalyashu77](https://avatars.discourse-cdn.com/v4/letter/m/8e7dd6/32.png) [@mittalyashu77](https://forum.freecodecamp.org/u/mittalyashu77)\
**Post date:** [October 31, 2017, 6:59pm UTC](https://forum.freecodecamp.org/t/counting-cards-challenge-javascript-doubt/141382/5 "2017-10-31T18:59:49Z")

</div>

Can someone explain the challenge? I didn’t understand the challenge only?

---

<div class="post-metadata">

**Author:** ![patagon.dev](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/patagon.dev/32/184205_2.png) [@patagon.dev](https://forum.freecodecamp.org/u/patagon.dev)\
**Post date:** [January 14, 2021, 9:00pm UTC](https://forum.freecodecamp.org/t/counting-cards-challenge-javascript-doubt/141382/6 "2021-01-14T21:00:32Z")

</div>

I came out with this solution, worked. Hope you find it useful.

```auto
var count = 0;

function cc(card) {

    const low = [2, 3, 4, 5, 6];
    const high = [10, 'J', 'Q', 'K', 'A'];
    if (low.includes(card)){
        count++;
    } else if (high.includes(card)) {
        count--
    }
    if (count <= 0) {
        console.log(count + " Hold");
        return count + " Hold";
    } else {
        console.log(count + " Bet");
        return count + " Bet";
    }

}

cc(2); cc(3); cc(7); cc('K'); cc('A');

```

---

<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 14, 2021, 9:09pm UTC](https://forum.freecodecamp.org/t/counting-cards-challenge-javascript-doubt/141382/7 "2021-01-14T21:09:58Z")

</div>

It is great that you solved the challenge, but instead of posting your full working solution, it is best to stay focused on answering the original poster’s question(s) and help guide them with hints and suggestions to solve their own issues with the challenge.

We are trying to cut back on the number of spoiler solutions found on the forum and instead focus on helping other campers with their questions and definitely not posting full working solutions.

You can post solutions that invite discussion (like asking how the solution works, or asking about certain parts of the solution). But please don’t just post your solution for the sake of sharing it.  
If you post a full passing solution to a challenge and have questions about it, please surround it with `[spoiler]` and `[/spoiler]` tags on the line above and below your solution code.

---

<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 14, 2021, 9:10pm UTC](https://forum.freecodecamp.org/t/counting-cards-challenge-javascript-doubt/141382/8 "2021-01-14T21:10:02Z")

</div>

Closed on January 14, 2021, 9:10pm UTC


