Counting Cards Issues

Tell us what’s happening:

Your code so far


var count = 0;

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

Challenge: Counting Cards

Link to the challenge:

I see three problems.

Firstly…

if (card<0){
  return "5" + " Bet";
}

Is card what you want to be checking here? Change that here and the other two places.

Secondly, do you really want to hardcode "5" here? Is that supposed to always be 5 or is it supposed to be based on a variable? Check the other two locations too.

Lastly, on this line, is “Bet” supposed to be the word? In the instructions it says:

The function will then return a string with the current count and the string … Hold if the count is zero or negative

When I fix those 3 things, the code passes for me.

1 Like

A post was merged into an existing topic: Card Counting – Help