Code for counting cards not working

So… um its not working for some reason, I know there is a better way of doing this but I just want to know what’s wrong with this code

var count = 0;

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

 // Only change code above this line

cc(2); cc(3); cc(4); cc('5'); cc('6');


User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.212 Safari/537.36.

Challenge: Counting Cards

Link to the challenge:

You have two syntax errors.

  1. = is for assignment
  2. That is not a valid way to write a comparison against multiple values
1 Like

Hi @Caydenlin !

A few issues.

The first issue is here

and here

I understand what you are trying to do but that is not the correct way to go about it.

You want to say if card equals 2 or if card equals 3, etc.
Right now your code says if 2 is assigned to card or 3 or 4.

This means equals ===
This means assignment. =

If you are going to use an if statement instead of a switch statement you will have to say if card equals 2 or card equals 3 or card equals 4.

if (card === 2|| card=== 3|| etc.etc.etc

Second issue is that once you return something then your function is done.
So you are not actually getting to this if statement down here.

You shouldn’t add returns here

You can just say count++ or count - -

Also, you don’t need to add this else if clause

So you can just delete that.

Once you make all of those changes then it should work properly.

I would suggest using console.log to check and make sure that you are getting the correct values.


Hope that helps!


I can’t give any more explanation than the good people who commented before.
But if you solve the underlined problems about this :
(card = 2|3|4|5|6)
and this :
(card = 10|"J"||"Q"||"K"||"A")

I suggest that for your first if, you can just put something like this :

if (a > 0 && b > 0);
and finish with your count++ that you already wrote

1 Like

thank you so much, it totally works now!

That makes a lot of sense, thanks!

1 Like

Ok, it works now! thx!

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