# Count cards // Pls help

Tell us what’s happening:

I do not know what is happening
Pls help me

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

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

cc(2); cc(3); cc(7); cc('K'); cc('A');

``````

User Agent is: `Mozilla/5.0 (Linux; Android 8.1.0; Infinix X5515 Build/O11019) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.89 Mobile Safari/537.36`.

Challenge: Counting Cards

Hi!

`+ "" +`
use space:
`+ " " +`

``````return count + " " + "Bet";

return count + " " + "Hold";
``````

It worked thanks alot
Pls
Can u clarify my understanding of *switch statement *
EXAMPLE
switch (card){
case 2:
case 3:
case 4:
case 5:
case 6:
case 7:
count++;
break;
What is the count at each of the above numbers

Hi!
!!!Without case 7: =>

switch (card){
case 2:
case 3:
case 4:
case 5:
case 6:
count++;
break;

For short code normally we use "if, if else, else’. When the code becomes larger and larger it is better practice to use 'switch-case ’ instead of lot of nested “if, else if, else” to be able to maintain a good overview!

In our case example an if-else will be enough to solve the challenge like this:

``````if (card >= 2 && card <= 6) {
card += 1;
}
else if {
//here same for the other values according to the challenge.
}
``````

But the challenge is only to show how ‘switch-case’ works.

As far as black jack is concerned, i have not the slightest idea!

Thanks
How did they obtain `5 Bet`
When each positive count is worth 1 count.
I hope it is not silly

Asking questions to understand is never silly!

As far I understand,
at the beginning is count = 0

According to the card-values you increment (count = count + 1) or decrement (count = count - 1)

1. Cards Sequence 2, 3, 4, 5, 6 should return `5 Bet`
• card 2 —> count2 = 1
• card 3 —> count3 = 1
• card 4 —> count4 = 1
• card 5 —> count5 = 1
• card 6 —> count6 = 1

total_count = 1 + 1 + 1 + 1+ 1 = 5

1. Cards Sequence 3, 7, Q, 8, A should return `-1 Hold`
• card 3 —> count3 = 1
• card 7 —> count7 = 0
• card Q —> countQ = -1
• card 8 —> count8 = 0
• card A ----> countA = -1

total_count = 1 + 0 - 1 + 0 - 1 = -1!

And so on.

1 Like

I have understood