Build a Card Counting Assistant

Can’t seem to pass this challenge. Why is this code not working?

let count = 0

const cc = (card) => {
  if (card === 2 || 3 || 4 || 5 || 6 ){
    count += 1
  } else if (card === 7 || 8 || 9) {
    count += 0
  } else if ( card === 10 || "J" || "Q" || "K" || "A"){
    count -= 1
  }

  if (count > 0) {
    return `${count}` + " Bet"
  } else if (count <= 0){
    return `${count}` + " Hold"
  }
}

Welcome back to the forum @ar.wiley805

You may need to brush up on your knowledge of the OR operator.

What happens when you use the following code:

console.log(5 === 2 || 3 || 4 || 5 || 6);

Happy coding

1 Like

Fun fact: I actually wrote myself a JS script once for card-counting purposes. I wanted to know, given some reasonable assumptions about the game, how often the shoe favors the player enough that he should be increasing his bets. I was surprised to discover the answer; I don’t remember it exactly but it was something like 20-30% of the time, the player should be increasing his bet. (I was also surprised at how little time it took to iterate over a million shoes to come up with a confident average.)

Now that I think about it, maybe that should be a coding challenge.

Thanks! I think I see what is going on here now. I’ll post again if I need any other assistance. Again thanks for you response.

3 Likes