Build a Card Counting Assistant - Build a Card Counting Assistant

Tell us what’s happening:

i cannot get the last two part of where 7 can be 1, i got confused there.

Your code so far

let count = 0

function cardCounter(card) {
  if(card >= 2 && card <= 6) {
    count++
    return `${count} Bet`
  } else if(card === 7 || card === 8 || card === 9) {
    count
    return `${count} Hold`
  } else if(card === 10 || card === "J" || card === "Q" || card === "K" || card === "A") {
    count--
    return `${count} Hold`
  }  else if(card === 2 || card === "J" || card === 9 || card === 2) {
    count--
    return `${count} Hold`
  }
}

console.log(cardCounter(2))
console.log(cardCounter(3))
console.log(cardCounter(4))
console.log(cardCounter(5))
console.log(cardCounter(6))
console.log(cardCounter(7))
console.log(cardCounter(8))
console.log(cardCounter(9))
console.log(cardCounter(10))
console.log(cardCounter("J"))
console.log(cardCounter("Q"))
console.log(cardCounter("K"))
console.log(cardCounter("A"))

Your browser information:

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

Challenge Information:

Build a Card Counting Assistant - Build a Card Counting Assistant

Remember that the Bet/Hold depends on the value that’s counted, not the last card.

The tricky part with that challenge isn’t really the switch statement, it’s keeping the count logic clean and returning the right string format every time. I messed it up at first by resetting the count inside the function. Once I kept count global and paid attention to when to say “Bet” vs “Hold,” it finally clicked.