Card Counting code not working - seems to match solution 1

I think I am slowly going insane. I have written this code as efficiently as I can given what I’ve reviewed so far, and it still isn’t running successfully. I even went so far as to do something I rarely do and checked the hints, and even first solution, only to find out that from staring and comparing, it looks to be identical. Maybe a fresh set of eyes could help show me something I did that is obvious and stupid. :smiley: Please and thanks!

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 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.108 Safari/537.36.

Challenge: Counting Cards

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

Exclude the `return “Change Me”; - not sure how that ended up in there.

You must concatenate the variable with the string as you learned in this challenge: https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/basic-javascript/constructing-strings-with-variables

So, your return sentese must be like:

return count + " Bet";
1 Like

You can also use template literals.

return `${someValue} and some text`;

https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/es6/create-strings-using-template-literals

1 Like

I will sleep better this evening, but hate myself silently. I forgot to sign in with my existing account and just decided to start over. No problem the first time. Thanks for the prompt reply!

1 Like

I would mark yours a solution as well. I forgot about embedded expressions. Thanks!