# Basic JavaScript - Counting Cards

Tell us what’s happening:
Describe your issue in detail here.

Your code so far

``````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+=1
break;
case 7:
case 8:
case 9:
count+=0
break;
case 10:
case 'J':
case 'Q':
case 'K':
case 'A':
count--
break;

}   if(count > 0){
return count + " Hold"

} else {
return count+" Bet"
}

// Only change code above this line
}

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

``````

isnt this code correct?

Challenge: Basic JavaScript - Counting Cards

Link to the challenge:

Please Tell us what’s happening in your own words.

Learning to describe problems is hard, but it is an important part of learning how to code.

Also, the more you say, the more we can help!

Isn’t my code correct?

Can you try saying more?

What tests are failing? What have you done to figure out why those tests are failing?

the above code is to pass all the below test cases

• Your function should return a value for count and the text (`Bet` or `Hold`) with one space character between them.

• Waiting:Cards Sequence 2, 3, 4, 5, 6 should return the string `5 Bet`

• Waiting:Cards Sequence 7, 8, 9 should return the string `0 Hold`

• Waiting:Cards Sequence 10, J, Q, K, A should return the string `-5 Hold`

• Waiting:Cards Sequence 3, 7, Q, 8, A should return the string `-1 Hold`

• Waiting:Cards Sequence 2, J, 9, 2, 7 should return the string `1 Bet`

• Waiting:Cards Sequence 2, 2, 10 should return the string `1 Bet`

• Waiting:Cards Sequence 3, 2, A, 10, K should return the string `-1 Hold`

but its not passing . Can you please help me with it?

What have you tried to figure out why these are failing?

Your issue is here

Reread the directions here to make sure you are returning the correct values for the correct conditions

The function will then return a string with the current count and the string `Bet` if the count is positive, or `Hold` if the count is zero or negative. The current count and the player’s decision (`Bet` or `Hold` ) should be separated by a single space.

Once you fix that, then it will pass

1 Like

i tried this same code in other compilers and getting the expected output but not in compiler of freecodecamp .

can you please describle more clearly what changes would i have to do?

right now your code says if count is positive then return count plus Hold

otherwise, return count plus Bet

But that is not what the instructions say

return the current count and the string `Bet` if the count is positive, or `Hold` if the count is zero or negative

Do you see where you went wrong?

1 Like

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.