Basic JavaScript: Counting Cards Challenge

Hello,

I’ve been trying to finish this challenge and all requirements are passed except this one:

Cards Sequence 2, J, 9, 2, 7 should return 1 Bet

My code:

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 += 1;
break;
case 7:
case 8:
case 9:
count = 0;
break;
case 10:
case “J”:
case “Q”:
case “K”:
case “A”:
count -= 1;
break;
}
if (count > 0) {
return count + " Bet";
} else {
return count + " Hold";
}

// Only change code above this line

}

Can someone help me or give me a hint as to why that only requirement is missing?
A similar one, Cards Sequence 2, 2, 10 should return 1 Bet is passed and the outcome is the same = 1 Bet.

Thank you in advanced,

Look at what you are doing for cases 7,8, and 9. You are resetting the variable ‘count’ to 0. It’s probably better if you don’t do anything for those cases :slight_smile:

2 Likes

Oh my…

Thanks a lot. That was indeed helpful and enough so i could finish it and passed all requirements.

I just changed it to count += 0; and it worked. I was saying that if 7, 8, 9 then count = 0 and that was reseting the var count back to 0, ignoring the previous + 1. Thank you so much @shimphillip

What do you mean @camperextraordinaire?
What would be a better option?

Thanks @camperextraordinaire, now i understood what you meant.

I thought that, for the purpose of the challenge it was required to put them in.