# Counting Cards problem

Can someone explain why my solution isn`t right:

``````let count = 0;

function cc(card) {
// Only change code below this line
if ((card === 2) || (card === 3) || (card === 4) || (card === 5) || (card === 6)) {
count = count + 1;
return count + "Bet";
}
else if ((card === 7) || (card === 8) || (card === 9)) {
return count + "Hold";
}
else if ((card === 10) || (card = 'J') || (card = 'Q') || (card = 'K') || (card = 'A')) {
count = count - 1;
return count + "Hold";
}
else {
return "Change Me";
}

// Only change code above this line
}

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

First of all, your output isnâ€™t quite right, put this at the bottom to see:

``````console.log(cc(2))
console.log(cc('K'))
console.log(cc('K'))
``````

Also, you `if/else` structure needs some attention - youâ€™re on the right path, but arenâ€™t quite there yet.

Also, remember that what you return shouldnâ€™t be based on the most recent card, but on what the count is after the most recent card.

1 Like

I checked the example you gave and it seems correct:
1 Bet
0 Hold
-1 Hold
Maybe I didn`t understand what the problem wants ( English is not my first language) but to my understanding the exercise requires that I keep track of all cards extracted to asses my chance that the next card is in the â€śgoodâ€ť or â€śbadâ€ť category.

Right, but the return value has nothing to do with the value of `card`

1 Like

Thank you both for your effort. Turns out my problem was I didn`t know how to use the console.log command to test my code. Once I did that I saw the problem with the hold/bet and managed to address the issue. The code looks like this now and it works:

``````let count = 0;
function cc(card) {
// Only change code below this line
if ((card === 2) || (card === 3) || (card === 4) || (card === 5) || (card === 6)) {
count = count + 1;
if (count > 0) {
return count + " Bet";
}
else {
return count + " Hold";
}
}
else if ((card === 7) || (card === 8) || (card === 9)) {
if (count > 0) {
return count + " Bet";
}
else {
return count + " Hold";
}
}
else if ((card === 10) || (card = 'J') || (card = 'Q') || (card = 'K') || (card = 'A')) {
count = count - 1;
if (count > 0) {
return count + " Bet";
}
else {
return count + " Hold";
}
}

else {
return "Change Me";
}
// Only change code above this line
}

``````

one of your issues was this, typo or distracted I think

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