# Counting Cards - Javascript Issues

**URL:** <https://forum.freecodecamp.org/t/counting-cards-javascript-issues/441791>\
**Category:** General\
**Created:** [January 21, 2021, 2:11am UTC](https://forum.freecodecamp.org/t/counting-cards-javascript-issues/441791 "2021-01-21T02:11:24Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![hbscope](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/hbscope/32/199027_2.png) [@hbscope](https://forum.freecodecamp.org/u/hbscope)\
**Post date:** [January 21, 2021, 2:11am UTC](https://forum.freecodecamp.org/t/counting-cards-javascript-issues/441791/1 "2021-01-21T02:11:24Z")

</div>

It’s late and I’m tired.  
Guide post for this challenge is locked so I’ll open a new topic.  
Someone please explain why this won’t work:

```auto
' var count = 0;

function cc(card) {

// Only change code below this line

if (cc == 2, 3, 4, 5, 6){

count +1;

}

if (cc == 7, 8, 9){

count = count;

}

if (cc == 10, 'J', 'Q', 'K', 'A'){

count -1;

}

if (count <= 0){

return count; "Hold";

}

if (count > 0){

return count; "Bet";

}

else {

return "Change Me";

}

// Only change code above this line

}

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

```

---

<div class="post-metadata">

**Author:** ![amejl172](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/amejl172/32/209703_2.png) [@amejl172](https://forum.freecodecamp.org/u/amejl172)\
**Post date:** [January 21, 2021, 2:20am UTC](https://forum.freecodecamp.org/t/counting-cards-javascript-issues/441791/2 "2021-01-21T02:20:57Z")

</div>

1. You’re not using `card` in the function.

---

<div class="post-metadata">

**Author:** ![Roma](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/roma/32/112899_2.png) [@Roma](https://forum.freecodecamp.org/u/Roma)\
**Post date:** [January 21, 2021, 2:47am UTC](https://forum.freecodecamp.org/t/counting-cards-javascript-issues/441791/3 "2021-01-21T02:47:05Z")

</div>

I’ve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.

You can also use the “preformatted text” tool in the editor (`</>`) to add backticks around text.

 ![Pre-formatted-text](https://global.discourse-cdn.com/freecodecamp/original/3X/1/b/1b18854f1059217f29370444396145cc3a0cd8ae.gif)

See [this post](http://www.freecodecamp.com/forum/t/forum-code-formatting/25574) to find the backtick on your keyboard.  
**Note:** Backticks (`) are not single quotes (’).

---

<div class="post-metadata">

**Author:** ![amejl172](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/amejl172/32/209703_2.png) [@amejl172](https://forum.freecodecamp.org/u/amejl172)\
**Post date:** [January 21, 2021, 2:55am UTC](https://forum.freecodecamp.org/t/counting-cards-javascript-issues/441791/4 "2021-01-21T02:55:14Z")

</div>

You can use Switch statement in this challenge.  
To make switch statement use

```auto
switch(card) {
}

```

in the end you can use if and else if to return the `count + ' Hold'` / `' Bet'`.

---

<div class="post-metadata">

**Author:** ![hbscope](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/hbscope/32/199027_2.png) [@hbscope](https://forum.freecodecamp.org/u/hbscope)\
**Post date:** [January 21, 2021, 10:49am UTC](https://forum.freecodecamp.org/t/counting-cards-javascript-issues/441791/5 "2021-01-21T10:49:09Z")

</div>

@Roma Thanks, I missed some.

I tried again, and as far as I can tell, my code is IDENTICAL to the one given as a solution, but it once again leads me dangerously close to breaking things, so someone please tell me why my thick skull doesn’t get this:

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

}

  return "Change Me";

  // Only change code above this line

}

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

```

---

<div class="post-metadata">

**Author:** ![Sky020](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/sky020/32/128093_2.png) [@Sky020](https://forum.freecodecamp.org/u/Sky020)\
**Post date:** [January 21, 2021, 11:02am UTC](https://forum.freecodecamp.org/t/counting-cards-javascript-issues/441791/6 "2021-01-21T11:02:36Z")

</div>

Hey there,

The function does not quite return what is asked for. Easiest way to debug, is to add this to the bottom of the editor:

```auto
console.log(cc(3));

```

Have a look at the output.

* * *

For future posts, if you have a question about a specific challenge as it relates to your written code for that challenge, just click the **Ask for Help** button located on the challenge. It will create a new topic with all code you have written and include a link to the challenge also. You will still be able to ask any questions in the post before submitting it to the forum.

Hope that helps

---

<div class="post-metadata">

**Author:** ![hbscope](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/hbscope/32/199027_2.png) [@hbscope](https://forum.freecodecamp.org/u/hbscope)\
**Post date:** [January 21, 2021, 11:07am UTC](https://forum.freecodecamp.org/t/counting-cards-javascript-issues/441791/7 "2021-01-21T11:07:27Z")

</div>

Literally the one space before Bet and Hold?  
Are you kidding me?

I’m increasingly unsure if I can even learn programming at this rate.

---

<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 21, 2021, 11:09am UTC](https://forum.freecodecamp.org/t/counting-cards-javascript-issues/441791/8 "2021-01-21T11:09:30Z")

</div>

why? it’s just the most common error

you’re not alone

[![](https://i.redd.it/8gwce0j02oa21.jpg) ](https://i.redd.it/8gwce0j02oa21.jpg)

---

<div class="post-metadata">

**Author:** ![Sky020](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/sky020/32/128093_2.png) [@Sky020](https://forum.freecodecamp.org/u/Sky020)\
**Post date:** [January 21, 2021, 11:11am UTC](https://forum.freecodecamp.org/t/counting-cards-javascript-issues/441791/9 "2021-01-21T11:11:44Z")

</div>

Exactly. This is what programming involves, but do not be discouraged by this. Everyone makes these mistakes, and all you need to do is make sure you try to debug.

I have seen this mistake often enough to know what to specifically look for, and now you have too. So, next time something does not work as you expected…debug (console.log is a JS developers friend)

---

<div class="post-metadata">

**Author:** ![hbscope](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/hbscope/32/199027_2.png) [@hbscope](https://forum.freecodecamp.org/u/hbscope)\
**Post date:** [January 21, 2021, 11:47am UTC](https://forum.freecodecamp.org/t/counting-cards-javascript-issues/441791/10 "2021-01-21T11:47:07Z")

</div>

@ILM Thanks, I needed that picture. I’m putting that one up on my second machine as a reminder .

@Sky020 So what you’re saying is that if I don’t get why my code doesn’t run, `console.log` at the end of the code will always give me an idea of why it doesnt?  
If so, why is that never explained in the curriculum? I feel like it would save a lot of headaches.

---

<div class="post-metadata">

**Author:** ![Sky020](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/sky020/32/128093_2.png) [@Sky020](https://forum.freecodecamp.org/u/Sky020)\
**Post date:** [January 21, 2021, 11:57am UTC](https://forum.freecodecamp.org/t/counting-cards-javascript-issues/441791/11 "2021-01-21T11:57:46Z")

</div>

> [@hbscope](#):
>
> If so, why is that never explained in the curriculum?

[Debugging | freeCodeCamp.org](https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/debugging/)

There has been some discussion about moving this further up the curriculum. It is just a bit hard to place/organise.

* * *

> [@hbscope](#):
>
> `console.log` at the end of the code will always give me an idea of why it doesnt?

Not always, but if I do not understand something, it is always my first point of call. \_Keep in mind, the placement of the `console.log` matters, and it is not always at the end of the script.

Hope this helps

---

<div class="post-metadata">

**Author:** ![hbscope](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/hbscope/32/199027_2.png) [@hbscope](https://forum.freecodecamp.org/u/hbscope)\
**Post date:** [January 21, 2021, 11:59am UTC](https://forum.freecodecamp.org/t/counting-cards-javascript-issues/441791/12 "2021-01-21T11:59:22Z")

</div>

Thanks, I understand.

---

<div class="post-metadata">

**Author:** ![cobrasesina121XD](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/cobrasesina121xd/32/199261_2.png) [@cobrasesina121XD](https://forum.freecodecamp.org/u/cobrasesina121XD)\
**Post date:** [January 21, 2021, 1:00pm UTC](https://forum.freecodecamp.org/t/counting-cards-javascript-issues/441791/13 "2021-01-21T13:00:52Z")

</div>

me alegro 🙂

---

<div class="post-metadata">

**Author:** ![hbscope](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/hbscope/32/199027_2.png) [@hbscope](https://forum.freecodecamp.org/u/hbscope)\
**Post date:** [January 21, 2021, 1:02pm UTC](https://forum.freecodecamp.org/t/counting-cards-javascript-issues/441791/14 "2021-01-21T13:02:31Z")

</div>

¿Que?  
Lo siento, no hablo Español.

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/freecodecamp/original/3X/e/1/e1c433102e34b46dfaa3e15d13ab9a514b127078.svg) [@system](https://forum.freecodecamp.org/u/system)\
**Post date:** [July 23, 2021, 1:02am UTC](https://forum.freecodecamp.org/t/counting-cards-javascript-issues/441791/15 "2021-07-23T01:02:37Z")

</div>

Closed on July 23, 2021, 1:02am UTC

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.
