# Counting Cards, not receiving check mark

Counting Cards, not receiving check mark
0

#1

Tell us what’s happening:
I’m getting every checkmark except Cards Sequence 3, 7, Q, 8, A should return -1 Hold
I don’t see why I’m not getting this as it is set up the same as every other check mark. Mabey it’s something obvious like spelling but I have bene looking for awhile now at cant pinpoint the problem.

``````
var count = 0;

function cc(card) {
// Only change code below this line
switch(card) {
case 2, 3, 4, 5, 6: return "5 Bet";
case 7, 8, 9: return "0 Hold";
case 10, 'J', 'Q', 'K', 'A': return "-5 Hold";
case 3, 7, 'Q', 8, 'A': return  "-1 Hold";
case 2, 'J', 9, 2, 7: return "1 Bet";
case 2, 2, 10: return "1 Bet";
case 3, 2, 'A', 10, 'K': return "-1 Hold";
}

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/67.0.3396.99 Safari/537.36`.

#2

You should not be hard-coding the return statements. If the card passed into the cc function is a 2, 3, 4, 5, or 6, why would you always return “5 Bet”? What gets returned has nothing to do with the card variable’s value and has everything to do with the count variable’s value. You need to be increasing and decreasing the value of count based on the card value and then returning the count value plus " Bet" if the count is greater than zero or " Hold" if the count is less than or equal to zero.

#3
``````switch(card) {
case 2, 3, 4, 5, 6: return "5 Bet";
case 7, 8, 9: return "0 Hold";
case 10, 'J', 'Q', 'K', 'A': return "-5 Hold";
case 3, 7, 'Q', 8, 'A': return  "-1 Hold";
case 2, 'J', 9, 2, 7: return "1 Bet";
case 2, 2, 10: return "1 Bet";
case 3, 2, 'A', 10, 'K': return "-1 Hold";
}
``````

You are not supposed to hard code each of the tests in. You are supposed to tell it what to do to the count for each possibility. You’re also using the `switch` incorrectly. Here’s something I wrote up for someone else:

``````function isAVowel(letter) {
switch (letter.toLowerCase()) {
case 'a':
case 'e':
case 'i':
case 'o':
case 'u':
break
case 'y':
break
default:
}
}
``````

You need to do something similar, listing out the different cards and what action should be taken. I would suggest grouping cards 2-6 in one where you add 1 to count, then 10-‘A’ where you subtract one, and then just default to do nothing (7-9).

Does that make sense?

#5

so based of what you said, my code is now this.

var count = 0;

function cc(card) {
// Only change code below this line
switch (card) {
case 2:
case 3:
case 4:
case 5:
case 6:
return (count + 1);
break;
case 10:
case ‘J’:
case ‘Q’:
case ‘K’:
case ‘A’:
return (count - 1);
break;
default:
(count + 0);
break;
}
if (count > 0) {return count + “Bet”}
else if (count <= 0) {return count + “Hold”}

// Only change code above this line
}

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

I am still not receiving any check marks though. Whats the problem?

#6

OK, you’re on the right track, a big improvement.

Consider the line:

``````return (count + 1);
``````

You don’t want to return count+1 out of the function. You just want to increment count. Do you remember how to increment a variable? You definitely don’t want to return there.

``````(count + 0);
break;
``````

You can omit these lines. “default” doesn’t need a break and you don’t want it to do anything so leave it blank. It’s good to have a default, but leave it blank.

``````if (count > 0) {return count + “Bet”}
else if (count <= 0) {return count + “Hold”}
``````

Both of those messages need a space before the word.

And I’m assuming that those smart quotes (curly) are just a symptom of cut and paste.

But if I make those changes, it passes.

#7

Thanks man, I find myself verry lost on the tests that make you find a solution to the problem without much guide, and you helped a lot. Cheers m8 and happy coding!