My codes not working

Tell us what’s happening:
Describe your issue in detail here.
I tried solving it with if statements and as well as switch statement, but neither of those seem to work. And I’m just not being able to find the mistake. Can someone please spot my mistake from the code?

  **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 += 1;
    break;
  case 7:
  case 8:
  case 9:
    count += 0;
    break
  case 10:
  case 'J':
  case 'Q':
  case 'K':
  case 'A':
    count -= 1;
    break;
}
if (count <= 0) {
  return count, "Hold";
}
else {
  return count, "Bet";
}

// Only change code above this line
}

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/94.0.4606.71 Safari/537.36

Challenge: Counting Cards

Link to the challenge:

Two things:

  • The return string needs to have a space between the count and Hold/Bet
  • Using a comma to combine the count and Hold/Bet isn’t doing what you intend. Try adding the following at the bottom and then look in the console pane below the editor to see what it gives you:

console.log(cc(1));

Do you know of another way to add a variable and string together so they make one string?

1 Like

Oh my god! It worked now. Thanks!
I added a space infront of “Hold” and “Bet”. Then I used the “+” operator instead of comma to concatenate. And it worked!
I think there’s only these two ways to add a string and a variable which returns another string. One is adding a comma between them and the other is adding a plus operator between the string and the variable. However, there might be other ways but I don’t know cuz I’m still a beginner.

This is actually not a method for adding a variable to a string, that’s why your original solution wasn’t working.

There are other ways beside the plus sign. I believe you will get to them as you progress in the course. But using a comma is not one of them.

I guess then I messed up with other languages.

I hope I’ll get to know more as I progress. Thanks.

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