Card Counting -- Help

var count = 0;

function cc(card) {

  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){

    console.log(count + " Bet");

    return;

  } else {

    console.log(count + " Hold");

    return;

  }

  // Only change code above this line

}

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

Hello there.

Do you have a question?

If so, please edit your post to include it in the Tell us what’s happening section.

The more information you give us, the more likely we are to be able to help.


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 (’).

The tests don’t care about what you console.log in your code, they only look at what your functions return.

I am working on the same problem. I was wondering why it’s not printing out things correctly such as the count and the string “Bet”.

var count = 0;

function cc(card) {

  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){
    console.log(count + " Bet");
    return;
  } else {
    console.log(count + " Hold");
    return;
  }
  // Only change code above this line
}

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

I don’t understand what you mean by “not printing out”. When I run your code, it prints out those strings to the console (open with something like ctrl-shft-J or ctrl-shft-I).

But as jsdisco points out, you are not supposed to print those out but return them from the function.

When I fix that, your code works.

Maybe I’m not understanding what you are asking.

1 Like

Do you mean its not printing in freecodecamp console place?

that is the same way i did it it is prettey simple actually

i do not undersand what you are saying at all @kevinSmith

if you write return; the function just returns undefined, but the instructions want you to return a specific value

ty @ieahleen now i understand