# Basic JavaScript - Counting Cards

Hi, i’m trying to get this exercise done but i don’t understand what’s wrong with the count.
If i call the function cc(10), this should give a count of -1 so it should return “-1 Hold”, but instead it’s returning “0 Hold”. Can someone please help me?

Thanks!

``````   **Your code so far**
``````
``````let count = 0;

function cc(card) {
// Only change code below this line
if (card <= 6){
count++;
} else if (card>= 7 || card <= 9){
count = count + 0;
} else if (card===10 || card=="J" || card=="Q" || card=="K" || card=="A") {
count--;
} if (count > 0){
return count + " Bet";
} else if (count <= 0){
return count + " Hold";
}
// Only change code above this line
}

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

console.log(cc(10));

``````
``````   **Your browser information:**
``````

User Agent is: `Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.0.0 Safari/537.36`

Challenge: Basic JavaScript - Counting Cards

You have a whole series of calls here, and tme effect on count is cumulative

Side note - this is very confusing formatting

Hi, you should take a look at the conditions you are using for your statements and also consider using a switch statement as that could make your code look much cleaner and avoid unnecessary steps. hope that helps : )

I think it returns 0 for 10 because of your previous else-if statement. A way around this would be a switch statement, hope that helps

A switch would not change how this code functions, only how the code is organized. A switch is not some superpower, it’s just an alternative way to represent this specific type of if-else logic.

Oh sorry, if I may have confused or mislead him or her.

Or here or and here?

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