Counting Cards - Javascript Issues

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:

' 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');'
  1. You’re not using card in the function.

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.

See this post to find the backtick on your keyboard.
Note: Backticks (`) are not single quotes (’).

1 Like

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

switch(card) {

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

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

var count = 0;

function cc(card) {

  // Only change code below this line

switch(card) {

case 2:

case 3:

case 4: 

case 5:

case 6:



 case 10:

  case 'J':

  case 'Q':

  case 'K':

  case 'A':



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');

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:


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

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.

why? it’s just the most common error

you’re not alone


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)

@ilenia 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.

Debugging |

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

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

Thanks, I understand.

me alegro :slight_smile:

Lo siento, no hablo Español.

1 Like

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