freeCodeCamp Challenge Guide: Counting Cards (https://forum.freecodecamp.org/t/freecodecamp-challenge-guide-counting-cards/16809):

Continuing the discussion from freeCodeCamp Challenge Guide: Counting Cards:

var count = 0;

function cc(card) {
// Only change code below this line
if(card === 2 || card === 3 || card === 4 || card === 5 || card === 6){
count++;
if (count > 0) {
return count + " Bet";
}else {
return count + " Hold";
}
}else if (card === 10 || card === ‘J’ || card === ‘Q’ || card === ‘K’ || card === ‘A’) {
count–;
if (count > 0) {
return count + " Bet";
}else {
return count + " Hold";
}
}else if (card === 7 || card === 8 || card === 9) {
count += 0;
if (count > 0) {
return count + " Bet";
}else {
return count + " Hold";
}
}
// Only change code above this line
}
// Add/remove calls to test your function.
// Note: Only the last will display
cc(2); cc(3); cc(7); cc(‘K’); cc(‘A’);

I was amazed at myself that this actually worked.

You can post solutions that invite discussion (like asking how the solution works, or asking about certain parts of the solution). But please don’t just post your solution for the sake of sharing it.

We have set your post to unlisted. Thanks for your understanding.

I am not able to understand the counting card concept, can anyone help me in explaining in parts of the code??

If you have questions about a challenge, you can create a forum topic with your code and an explanation of what you need help with.

I did it this way, but it took me some time to analyze:
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++;

  break;

case 10:

case 'J':

case 'Q':

case 'K':

case 'A':

  count--;

  break;

}

var hb = “Hold”

if (count > 0) {

hb = "Bet";

}else if (count < 1) {

hb = "Hold";

}

return count + " " + hb;