Counting Card Problem

Counting Card Problem
0

#1

I dont know why my solution is not working, could someone take a look?

Thanks!

Here is my solution :
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
}

// Add/remove calls to test your function.
// Note: Only the last will display
cc(2); cc(3); cc(4); cc(5); cc(6);


#2

Do you really want to reset count to 0 if the card is a 7, 8, or 9? Do you really need to do anything with count if the card is a 7, 8, or 9? Does your select statement even need cases for 7, 8, or 9?

Also, make sure your return statement returns a string like “5 Bet” and not “5Bet”.


#3

Hey Randell,
Thanks for the answer!!

I removed the 7,8,9 cases and it worked.
Although i dont understand why it wouldnt work with count = 0. Wouldnt it just add 0 to the count?

Thanks!


#4

There is a difference between adding 0 to count and setting the value of count to 0.

var count = 10;
count += 0; // count is still 10

count = 0; // count is now 0

#5

I understand now!

Thanks!