Build a Card Counting Assistant - Build a Card Counting Assistant

Tell us what’s happening:

Hi there,

I would appreciate any pointers in the right direction. I have been unable to get my code to pass steps 8 and 9.

  1. After the cards 2, “J”, 9, 2, then calling cardCounter(7) should return the string 1 Bet.
  2. After the cards 2, 2, then calling cardCounter(10) should return the string 1 Bet.

Saw someone asked a question in the forum with similar code using if/elseif statements but can’t quite pinpoint where I have deviated.

Your code so far

let count = 0;

function cardCounter(card){
  if (card ===2 || card === 3 || card === 4 || card === 5 || card ===6 ) {
    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") {
    return `${--count} Hold`
 }

}

cardCounter(2)
cardCounter(3)
cardCounter(4)
cardCounter(5)
console.log(cardCounter(6))

count=0;
cardCounter(7)
cardCounter(8)
console.log(cardCounter(9))

count=0;
cardCounter(10)
cardCounter("J")
cardCounter("Q")
cardCounter("K")
console.log(cardCounter("A"))

count=0;
cardCounter(3)
cardCounter(7)
cardCounter("Q")
cardCounter(8)
console.log(cardCounter("A"))

count=0;
cardCounter(2)
cardCounter("J")
cardCounter(9)
cardCounter(2)
console.log(cardCounter(7))

count=0;
cardCounter(2)
cardCounter(2)
console.log(cardCounter(10))

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

Welcome to the forum @oludolapo

  1. The cardCounter function should return a string with current count and the string Bet if the count is positive.

How does your function implement user story 8?

Happy coding

Thank you so much for the pointer. I was overlooking the requirement to make the return conditional on a positive or negative count. Very much appreciate your quick response. Thank you.

1 Like