# Solved!Counting Cards Not Working

Tell us what’s happening:
I have tried multiple versions of solutions, and while they haven’t worked, I am now wondering if I should somehow traverse an array or possibly linked list to get this done. I’ve tried various if/else if/else statements. I’ve tried switch statements. I’ve also tried the solution, but I haven’t figured out what to change to make it work. Nothing works.

``````
var count = 0;

function cc(card) {
// Only change code below this line
switch(card){
case 2:
count+1;
break;
case 3:
count+1;
break;
case 4:
count+1;
break;
case 5:
count+1;
break;
case 6:
count+1;
break;
case '10':
count-1;
break;
case 'J':
count-1;
break;
case 'Q':
count-1;
break;
case 'K':
count-1;
break;
case 'A':
count-1;
break;
}
if (count > 0){
return count + "Bet";
} else {
return count + "Hold";
}
//___________other versions
if (count >0 &&<7){
card = card+1;
return card + "Bet"; //needs count positive sign checker
} else if (count ==0) {
return card; //may need other condition
} else (count <0){
card = card-1;
return card + "Hold";
}

//-------
if (count > 0) {
if (card >0 &&<7){
count = card+1;
count++
return count + "Bet"; //needs count positive sign checker
} else if (card >= 7 && <=9) {
return count; //may need other condition
} else (card > 9){
count = card-1;
count--;
return card + "Hold";
}
return count + "Bet";
} else {
return count + "Hold";
}

// Only change code above this line
}

// Note: Only the last will display
cc(2); //cc(3); cc(7); cc('K'); cc('A');
``````

User Agent is: `Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:61.0) Gecko/20100101 Firefox/61.0`.

There is a solution in the hint page.

`card >0 &&<7``card>0 && card<7` and
`else` does not accept a boolean expression.
check out js doc on MDN about if control flow .

Red wavy lines under your code means your code is wrong, hover on it to see the error message.

FCC is more like a problem site, always check corresponding doc site before solving problems, this make your knowledage more solid.

for the first version you forgot to assign values back to `count` variable, ex : `count = count - 1`, and for the return value it needs a space between the count and the message , ex : `3 Bet`

2 Likes

Thanks!
This is the code that ended up working. I had tried doing the count++, count-- from the solution before I even made this forum post. I guess count = count + 1 is what worked.

Here is the code that passed:
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 = count + 1;
break;
case 10:
case ‘J’:
case ‘Q’:
case ‘K’:
case ‘A’:
count = count - 1;
break;
}
if (count > 0){
return count + " Bet";
} else {
return count + " Hold";
}

1 Like

Thanks for the recommendations.

This really helped! Thank you!

1 Like