Basic JavaScript - Counting Cards

Tell us what’s happening:
Describe your issue in detail here.
please someone to collect me, it seems i cant find my error

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

function cc(card) {
// Only change code below this line
if (card >= 2 && card <= 6){
count = +1;
}else if(card == 7 || card == 8 || card == 9){
count = 0;
}else(card == 10 || card == "j" || card == "Q" || card == "K" || card == "A"){
count = -1;
}
if(count > 1){
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');
  **Your browser information:**

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/104.0.0.0 Safari/537.36

Challenge: Basic JavaScript - Counting Cards

Link to the challenge:

I see a couple of things. First of all, you are getting this error:

SyntaxError: unknown: Missing semicolon. (9:77)

   7 | }else if(card == 7 || card == 8 || card == 9){
   8 | count = 0;
>  9 | }else(card == 10 || card == "j" || card == "Q" || card == "K" || card == "A"){
     |                                                                              ^
  10 | count = -1;
  11 | }
  12 | if(count > 1){

That is because of this:

}else(card == 10 || card == "j" || card == "Q" || card == "K" || card == "A"){

else doesn’t have conditions. I does not expect a logical expression after else so it is getting confused.

Also, card == "j". Is that what you want?

Also, you should use === instead of == unless you specifically want the latter (you almost never should).

Also, I don’t think these lines:

count = +1;
count = 0;
count = -1;

are doing what you think they are. If they are, then you are misunderstanding.

You also have an issue with your output strings. You can see one of the problems by testing it like this:

console.log(cc(2));
console.log(cc(3));
console.log(cc(7));
console.log(cc('K'));
console.log(cc('A'));

The other issue is that you aren’t exactly giving the required string.

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