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
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 : )
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.