Tell us what’s happening:
I already got the test, but I don’t really how it worked.
I hope I find someone who understands what I’m trying to point out.
Like, I think I know how the cards got calculated, like this:
if we have cards:
K, 8, 2, 3, Q, A
That means, we have:
-1, 0, +1, +1, -1, -1 = -3+2 = -1
==> -1 Hold
But I think, that calculation I did it’s not reflected in the code
OR
Is it that
count++ means adding up all the positive cards, say five of them (2,3,4,5,6) making +5
and
count-- means adding them up also (10, “J”, “Q”, “K”, “A”) making -5
And, by chance, we have mixed cards like 2,7, Q, 5,J how come we got the output 0 Hold
But. this following code doesn’t depicts the calculation:
if (count > 0) {
return count + " Bet";
} else {
return count + " Hold";}
I HOPE I FIND JUSTICE WITH THIS COMBAT I’M HAVING. PLEASE HELP ME. THANKS.
That’s my code below:
let 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 (count > 0) {
return count + " Bet";
} else {
return count + " Hold";}
}
// Only change code above this line
cc(2); cc(3); cc(7); cc('K'); cc('A');
Challenge: Basic JavaScript - Counting Cards
Link to the challenge: