Build a Card Counting Assistant - Build a Card Counting Assistant

Tell us what’s happening:

I need help on requirements 4, 6, 7, 8, 9 and 10. I don’t really understand what they mean

Your code so far

let count = 0;
function cardCounter(card) {
  count = 1 < card > 7 ? count++ : card === 7 || 8 || 9 ? count : card === 10 || "J" || "Q" || "K" || "A" ? count-- : undefined;
  return count > 0 ? `${count} Bet` : count <= 0 ? `${count} Hold` : undefined;
}

console.log(cardCounter(3));


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

4. Cards 2, 3, 4, 5, 6 should increment the count by 1

  • These are low cards that are favorable for the player

6. Cards 7, 8, 9 should not change the count

  • These are neutral cards

7. Cards 10, J, Q, K, A should decrement the count by 1

  • These are high cards that are unfavorable for the player

8. Return the current count and the string “Bet” if count is positive, or “Hold” if count is zero or negative

  • Format: “X Bet” or “X Hold”

9. Reset the count to 0 when the function is called

  • Each call should start fresh, not keep accumulating from previous calls

10. Do not return an array

  • Just return a string like “5 Bet” or “-2 Hold”

Issues with Your Current Code:

  1. Logical condition syntax is wrong: 1 < card > 7 doesn’t work in JavaScript

  2. String comparisons for face cards won’t work: card === "J" || "Q" needs proper syntax

  3. The ternary operator is overly complex and incorrect

  4. Count doesn’t reset to 0 (requirement 9)

  5. **Face cards comparison syntax is wrong

    Corrected Solution

code removed by moderator

@Tiger2

It is great that you solved the challenge, but instead of posting your full working solution, it is best to stay focused on answering the original poster’s question(s) and help guide them with hints and suggestions to solve their own issues with the challenge. How to Help Someone with Their Code Using the Socratic Method

We are trying to cut back on the number of spoiler solutions found on the forum and instead focus on helping other campers with their questions and definitely not posting full working solutions.

check if count is updating as you think it should
add console.log(count) right below this line, and call the function with various cards, check if it changes as it should

1 Like

What is the difference between using this method and using if…else if?

if/else if is more readable when you need to nest them, but you can use ternaries here if you can write the conditions well

Okay thanks. I had gemini tell me what I had wrong. Apparently, JavaScript doesn’t allow comparison of more than two values at a time.
I feel like I saw this somewhere before but I forgot it.
Thanks anyway :+1: