Counting Cards Challenge - Stuck

What do i wrong here?:

Your code so far


var count = 0;

function cc(card) {
  // Only change code below this line
  if (count > 1) {
    return 2, 3, 4, 5, 6 + " Bet";
  } else if (count == 0) {
    return 7, 8, 9 + " Hold";
  } else if (count < 0) {
    return 10, 'J', 'Q', 'K', 'A' + " Hold";
  }
  
  return "Change Me";
  // 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; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.100 Safari/537.36.

Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/basic-javascript/counting-cards

@Mr_Li,

if (count > 1) {
    return 2, 3, 4, 5, 6 + " Bet";

This part of your code means, if the count is greater than one, return the integers 2, 3, 4, 5, 6 and the string Bet.

The challenge is only looking for something like the following to be returned:

Example Output

-3 Hold or 5 Bet

Also, I don’t see where you’re updating the count variable in your code, as stated in the challenge instructions:

… increment or decrement the global count variable according to the card’s value (see table).

Read through the challenge instructions again and let me know what parts you need help with.

Thank you for your reply,

I have changed my code:
I think it is working now?

var count = 0;

function cc(card) {
  // Only change code below this line
  if (card > 0) {
    count++;
    return 2, 3, 4, 5, 6 + " Bet";
  } else if (card == 0) {
    return 7, 8, 9 + " Hold";
  } else if (card < 0) {
    count--;
    return 10, 'J', 'Q', 'K', 'A' + " Hold";
  }
  
  return card;
  // Only change code above this line
}

Nope it doesn’t works.

1 Like

You’re taking a bit of a wrong approach. I recommend you look through this topic as I’ve already explained some things there, one of the users also had a problem with completing this challenge:

1 Like

@Mr_Li, maybe thinking about your return statements will help along with reading through the comments in the topic @Gigusek shared.

What do you think this code does?

return 2, 3, 4, 5, 6 + " Bet";

As a hint, in my tests, it will always return 6 Bet regardless of the value of count or anything else.