Basic JavaScript - Counting Cards

Tell us what’s happening:

Hi, Please assist I don’t understand what I’m doing wrong.

My code is as follows so far

Your code so far

let count = 0;

function cc(card) {
  // Only change code below this line
if (card > 1 && card < 7) {
  count++;
} else if (card == 10 || card == "J" || card == "Q" || card == "K" || card == "A") {
  count--;
}
if (count > 0) {
return count + "Bet";
} else {
return count + "Hold";
}
  return "Change Me";
  // Only change code above this line
}

cc(2); cc(3); cc(7); cc('K'); cc('A');

Your browser information:

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

Challenge Information:

Basic JavaScript - Counting Cards

Try using console.log(cc(2)) to see what you are missing

Hi @ambradnum

This is still unclear to me.

// console output
1Bet

And what does the error message (or the instructions) say the result should be?

This is the error message:

Your function should return a value for count and the text (

Bet

or

Hold

) with one space character between them. Cards Sequence 2, 3, 4, 5, 6 should return the string

5 Bet

Cards Sequence 7, 8, 9 should return the string

0 Hold

Cards Sequence 10, J, Q, K, A should return the string

-5 Hold

Cards Sequence 3, 7, Q, 8, A should return the string

-1 Hold

Cards Sequence 2, J, 9, 2, 7 should return the string

1 Bet

Cards Sequence 2, 2, 10 should return the string

1 Bet

Cards Sequence 3, 2, A, 10, K should return the string

-1 Hold

These are the instructions,

You will write a card counting function. It will receive a card parameter, which can be a number or a string, and increment or decrement the global count variable according to the card’s value (see table). The function will then return a string with the current count and the string Bet if the count is positive, or Hold if the count is zero or negative. The current count and the player’s decision (Bet or Hold ) should be separated by a single space.

Hint
Do NOT reset count to 0 when value is 7, 8, or 9.
Do NOT return an array.
Do NOT include quotes (single or double) in the output.

Compare to

How is it different?

1 Like

Hi @JeremyLT

I’ve now added the space but still results (If thats what you implying)
// console output
1 Bet

Which tests are failing now? What is your new code?

Sorry @JeremyLT These are the ones failing now.

Your function should return a value for count and the text (

Bet

or

Hold

) with one space character between them. Cards Sequence 7, 8, 9 should return the string

0 Hold

Cards Sequence 10, J, Q, K, A should return the string

-5 Hold

Cards Sequence 3, 7, Q, 8, A should return the string

-1 Hold

Cards Sequence 3, 2, A, 10, K should return the string

-1 Hold

What is your code now?

@JeremyLT

Thank you I have found the solution. It was just the spacing between the count and “Bet” as well as “Hold”.

Thank you so much I had totally missed that

1 Like

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