Trouble with Counting Cards

Tell us what’s happening:

I could almost swear I’ve got this typed out almost right, but none of the boxes are checking. I fixed the syntax, and I thought I understood the logic of the program. What am I missing?

``````
var count = 0;

function cc(card) {
// Only change code below this line
if (card >= 2 && card <= 6) {
count++;
return count + "Bet";
} else if (card >= 7 && card <= 9) {
count += 0
return count + "Hold";
} else if (card === 10 || card === 'J' || card === 'Q' || card === 'K' || card === 'A') {
count--;
return count + "Hold";
}
else
return "Change Me";
// Only change code above this line
}

// Note: Only the last will display
cc(2); cc(3); cc(7); cc('K'); cc('A');
``````

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

The devil is in the details. You’re returning the various values, but you actually have no idea what it is you’re returning. What do you think

`````` return count+"Hold";
``````

is going to return? Remember, `count` is a number, let’s say `12` – what do you think is going to be output? Does it look like “`12 Hold`”? Close, but a TEEEENY tiny bit different.

1 Like

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. The current count and the player’s decision ( `Bet` or `Hold` ) should be separated by a single space.

Can you be sure that if the card is 2-6 you always Bet, if it’s 7-10, J, Q, K, A you always Hold?

1 Like

I know there’s something I’m overlooking. I’ll try it again after I eat dinner. Thank you for the help without giving away the answer immediately.

If you’re using that spoiler like how I think you are, that’s very clever.

I still couldn’t figure out what the hell was wrong. I fixed the spacing issue, but then I had to fix another issue, then it got over-complicated, and then I kept getting a syntax error from trying to start an `if` statement, and then I looked at an answer and saw that I should have used the switch technique that I was supposed to have learned from the other lessons, and I think I’m just going to go back over the basics of JavaScript from the very beginning of the curriculum.

You don’t need the switch here, can be used, but don’t need it

Have you solved the issue I brought up in my previous post?

No, I’m starting from the beginning of the curriculum.

You don’t need any other JavaScript feature than what you have already used in the challenge

Good luck with restarting!
Know that there is nothing wrong with references past lessons and the documentation (the MDN is your friend) or googling things. Every experienced developer still need to consult the documentation every day, you can’t (and don’t have to) remember everything)

And, if you solve it with the switch operator I still recommend that you try to fix the code you have here