Build a Card Counting Assistant - Lab says pass, console says otherwise for certain tests

Tell us what’s happening:

The lab environment accepts my code as a solution and says it passes all tests, but according to the console, it doesn’t pass all of them.

Here are the tests the solution does NOT pass:

  • After the cards 2, 3, 4, 5, then calling cc(6) should return the string 5 Bet. (Output is: 1 Bet)

  • After the cards 10, “J”, “Q”, “K”, then calling cc(“A”) should return the string -5 Hold. (Output is: -1 Hold)

  • After the cards 2, “J”, 9, 2, then calling cc(7) should return the string 1 Bet. (Output is: 0 Hold)

  • After the cards 2, 2, then calling cc(10) should return the string 1 Bet. (Output is: -1 Hold)

I’m not completely satisfied here. Sure, I gave a “passable solution”, but the code technically still doesn’t work. Is there an extra string I need to return? Some math that I’m missing? Not sure which direction to take to make the solution complete.

I appreciate the help in advance. Cheers.

Your code so far

let count = 0

function cc (card) {
  if (card >= 2 && card <= 6) {
    ++count;
  } else if (card >=7 && card <=9) {
    count;
  } else if (card === 10 || card === "J" || card === "Q" || card === "K" || card === "A") {
   --count; 
  }

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

let valueDecision = cc()
console.log(valueDecision)


Your browser information:

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

Challenge Information:

Build a Card Counting Assistant - Build a Card Counting Assistant

You need to handle the previous cards, too. Look at the tests. Plus, your call to cc is not passing in an argument.

As far as “handling the previous cards”, I would have to pass those in some kind of sequence. So perhaps there’s a variable that can be changed to accept a value that is a sequence of cards?

For my call, I left it blank so that I could pass arguments for testing at my leisure.

You can just do it like this:

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

or you could create another function to handle an array of previous cards before you call cc().

Make sense?

Wow, that’s a lot simpler than I anticipated. :sweat_smile: :rofl:

I could come up with some kind of function that passes a specific sequence through, and calling that function spits out the decision, but just for testing purposes…gosh I don’t know why I didn’t think just calling the cards line by line in sequence like that would’ve resulted in what was required. Oy.

Thank you!