Counting Cards is giving me a hard time :(

Hiya - so I’ve tried this two ways both with a result of 0Hold:

  case (card >=2 && card <= 6):
  count += 1;
    break;
    case (card >= 7 && card <=6):
    count++;
    break;
    case (card =10 || ('J', 'Q', 'K', 'A')):
    count--;
    break;
    
}
  if (count > 0){
    return count + "Bet";
  }
    else {
    return count + "Hold";

And this way with the same if else declarations:
```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 --;
    break;

I've read every post on this and understand all the solutions people have come to but can't seem to pass this challenge. Any tips / guidance would be appreciated!

Case 7 through 9 is not required because it does not change the count

Edit: may also need a space before the string in your return: " Bet". That’s what I was stuck on for this challenge, a simple space.

1 Like

So there’s a few things I noticed …

case (card >= 7 && card <=6):

So how can a card be greater than or equal to 7 and less than or equal to 6. This case isn’t going to do anything …

[quote=“anothermiller, post:1, topic:60198”]
case (card =10 || ('J', 'Q', 'K', 'A')): [/quote]

And that’s not going to work how you think.

Firstly, you are assigning card a value of 10 (you only have one =, you need 2 or preferably three for a strict equal check).

Secondly, you can’t compare values that way. This: ('J', 'Q', 'K', 'A') evaluates to A, always.

If you want to compare them each, then that’s going to be:

case ( card === 10 || card === 'J' || card === 'Q' || card === 'K' || card === 'A' ):

Alternatively you could define a string at the beginning:

const face_cards = '10JQKA';

and use:

case ( face_cards.includes( card ) ):

I know 10 isn’t a face card, but … oh well. :slight_smile:

Hope that helps!

hie,

There will be three conditions:

1st one you got right…
2nd can be -> else if(card>6 && card <10) then count=count+0;
3rd you decrement count by 1.(include this in else part).

:slight_smile:

Strictly speaking, none of the above answers should pass the test because we were asked to return a string, so count needs to be converted using .toString(). This may sound pedantic but it had me confused for a while, because we have not been shown how to use this method yet in the course. There have been a number of other quibbles I had about earlier parts of the course - how do I make these concerns known?

And sorry I forgot to say, that I agree that what is probably making your code fail is the missing space in your text. :slight_smile:

Well my answer doesn’t address return values, just case checking. :slight_smile:

As to making your concerns known, FCC is an open source project, you’re welcome to submit pull requests to pretty much any aspect of it!

Hey,

It is clearly written in the question the function should return a string along with the current count…
so
return count + " Hold";
works fine.
And it does pass the test.
You can try…:slight_smile:

Hi

Like I said, I am being pedantic but to quote from the actual question:
“The function will then return a string with the current count and the string “Bet” if the count is positive, or “Hold” if the count is zero or negative.” This says, to re-word, current count as a string and the string “Bet” or “Hold”. I don’t think I am mis-interpreting the question, but “no sweat” as either answer was accepted. I will make my next contribution to the forum more positive/useful :-))

Hi Ray,

I didn’t understand your objection earlier, or I would have mentioned this.

Just to be clear: Javascript automatically casts a number as a String when you add it to a string.

return count + ' Bet'; is the same as return count.toString() + ' Bet';

A very simple example:

Hi Micheal

Thanks for that explanation. I don’t think that this was mentioned in the course. I retract my previous “complaint” (and replace it with the objection that this was not made clear in the course! ? No. I will drop the matter).

Thanks again. :smile:

No problem at all!

FCC is by no means a completely comprehensive, all you need source for canonical information about every nuance of the language. (And I don’t think they intend to/should be).

The closest thing to a full, canonical reference would be the language spec itself … but, a more user friendly resource and something I refer to constantly, is the Mozilla Developer Network. They have great documentation on all aspects of JavaScript, the DOM, web APIs, along with examples.

I’ve made it a habit, whenever I do a search, to append ’ MDN’ to the search string so that I’m more likely to wind up there than anywhere else.

I also spend time simply browsing there to better get a feel for methods and APIs I don’t currently know about.

Regards,
Micheal