Counting Cards Javascript Challenge

Tell us what’s happening:
Hello Guys, I decided to follow the instructions from the “Problem Explanation” but its not working, some one can please help me with this problem. I cant see what i’m doing wrong

Your code so far


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
}

// 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 (Macintosh; Intel Mac OS X 10_14_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.86 Safari/537.36.

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

It looks like a formatting issue with your return string:

this:

    return count + "Bet";

    return count + "Hold";

Will return a string without spaces, so for example (n whatever count value is)

"nBet"
"nHold"

While the tests expect a spaces in the return:

"5 Bet"

Hope it helps :+1:

1 Like

If count is 2 this return 2Bet, if it is -1 this return -1Hold

The current count and the player’s decision ( Bet or Hold ) should be separated by a single space.

1 Like