Basic JavaScript: Counting Cards; What Am I Doing Wrong?

Tell us what’s happening:
I’ve seen people solve these a few different ways, but each time I try to modify my code to look more to theirs, I feel like I just get further from solving it. Can anyone lend a pair of eyes and help me troubleshoot?

Your code so far


var count = 0;

function cc(card) {
// Only change code below this line
var bet = "";
switch (card) {
case 2:
case 3:
case 4:
case 5:
case 6:
count = count + 1;
break;
case 7:
case 8:
case 9:
count = count + 0;
break;
case 10:
case 'J':
case 'Q':
case 'K':
case 'A':
count = count - 1;
break;
}
if (count == 0) {
return (count + "Hold");
} else if (count < 0) {
return (count + "Hold");  
} else if (count >= 1) {
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/86.0.4240.183 Safari/537.36.

Challenge: Counting Cards

Link to the challenge:

hey @sinkshipsink,

Your solution works but you need to add spaces in your text or it will fail the tests.

like this…

return (count + " Hold");

I figured it would have been a silly rule that I was overlooking. Can you explain the reasoning behind the spacing?

Is it because return (count + “hold”); is logging it as “CountvalueHold” rather than it logging as "Countvalue Hold " ?

2 Likes

That’s exactly what’s happening. Without the space the output isn’t super human readable.

You can see for yourself by adding

console.log(cc());

at the end of your code.

1 Like