Tell us what’s happening:
Even though I use 7,8,9 in the switch case and just put count in it as it is (without changing), the code is still running. But according to me, it should not pass all the test cases.
Explanation with an example:
Once I call, say, cc(2), the value count is set to 1 GLOBALLY. Right?
Now when I call cc(7), since the count is not being changed in this case, it’s value should still be 1 which is >0 and hence, our function should return “Bet” which is not the happening here.
Please help me wrapping my head around this.
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 7: case 8:
case 9:
count; break;
case 10: case 'J':
case 'Q': case 'K':
case 'A':
count--; break;
}
var holdBet;
if(count>0){
holdBet = "Bet"
}else{
holdBet = "Hold"
}
return count + " " + holdBet;
// 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/88.0.4324.150 Safari/537.36
.
Challenge: Counting Cards
Link to the challenge: