What is my mistake on Counting Cards

let count = 0;

function cc(card) {

    return (card >= 2 && card <= 6) ?

        `Bet ${count++}` :

        (card === "J" || card === "Q" || card === "K" || card === "A") ?

            `Hold ${count--}` : " "


I’ve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.

You can also use the “preformatted text” tool in the editor (</>) to add backticks around text.

See this post to find the backtick on your keyboard.
Note: Backticks (`) are not single quotes (’).

First of all, always include a link to the challenge so we don’t have to go hunting. Or use the Get Help -> Ask for Help button and it will do it for you.

A good programmer is a good debugger. And a good debugger is a good detective.

One of my first steps is to log things out.

What happens if I add this at the end?


I get:

Hold 0
Hold -1
Hold -2

Is that what we expect? I would expect that first one to be -1. You may want to review increment operator. There is a gotcha when you use it inline - easy to fix, but it often confuses beginners.

There is another big problem, but try logging out the returns for different values and see what you get.

Try to work on your debugging skills and check back if you get stuck.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.