# Counting Cards w/ switch

Counting Cards w/ switch
0
#1

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 ++;
return '5 Bet';
break;
case 7:
case 8:
case 9:
count += 0;
return '0 Hold';
break;
case 3:
case 7:
case 'Q':
case 8:
case 'A':
count --;
return '-1 Hold';
break;
case 10:
case 'J':
case 'Q':
case 'K':
case 'A':
count = count - 5;
return '-5 Hold';
break;
case 2:
case 'J':
case 9:
case 2:
case 7:
count = count + 1;
return '1 Bet';
break;
case 2:
case 2:
case 10:
count = count + 1;
return '1 Bet';
break;
case 3:
case 2:
case 'A':
case 10:
case 'K':
count = count -1;
return '-1 Hold';
}

return "Change Me";
// Only change code above this line
}

// Add/remove calls to test your function.
// Note: Only the last will display
cc(2); cc(3); cc(7); cc('K'); cc('A');
``````

Your browser information:

Your Browser User Agent is: `Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:56.0) Gecko/20100101 Firefox/56.0`.

Link to the challenge:

0 Likes

#2

could quite figure this out. any help would be great.

0 Likes

#3

Oh no no! you are trying to hard code the values of the test run into your program… This is not how it works. You have to make function that accepts something and gives a output corresponding to it. It has to work with any random value.

To help you start. Consider three conditions here:

If card value <= 6 and >=2 -, add 1 to count
Else if card value >= 7 and <=9 , do nothing to count.
else if card value >9 , subtract 1 from count.

For each condition do something to count or do nothing and return `count + "Bet" OR count + "Hold"` depending upon the current value of count.

Hope u understood

0 Likes