Help with Counting Cards

Tell us what’s happening:
Dear All,
Good nights,
I´m having troubles solving this challenge, would anyone please give me some orientation about how to solve it, i don´t understand basically how to put 5 and Bet together,
i tried to put : result 5 + “Bet”; (but it did not work),
thank you so much in advance to you all,
Kind regards,
Ivonne

Your code so far


var count = 0;

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





    // Only change code above this line


// Add/remove calls to test your function.
// Note: Only the last will display
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/77.0.3865.90 Safari/537.36.

Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/basic-javascript/counting-cards

When performing string concatenation you should account also for white spaces.
Consider the following example:

var n = 1;

n + 'Bet' // '1Bet'
n + ' Bet' // '1 Bet'

The tests will look for an exact match, for instance

'5Bet' !== '5 Bet' 

Try fixing the white spaces, and see where you go from there.
Hope this helps :+1:

Dear @Marmiz,
Good mornings,
Thank you so much for your fast reply, i appreciate it, i fixed the problem,
i will be careful with the white spaces in the string concatenation,
I wish you a lovely day @Marmiz,
Kind regards,
Ivonne

Here’s how I did it - I just used that case statement.

<redacted>

don’t give out the answers the mod might haunt u :frowning:

1 Like

I won’t - I just put it in to help.

Dear @artistpw,
Thank you so much for your help,
i appreciate it,
I wish you a wonderful day, and thank you so much for the orientation,
Kind regards,
Ivonne :slight_smile:

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.

If you want to compare your solution to others, use the Get a hint button on the challenge and there are alternative solutions you can compare yours to. Also, you can probably search older posts using the forum search feature or google the challenge name and find more there.

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.

Thank you for understanding.

You may need to remove

else if (card >= 7 && <= 9) 
{count =0};

I think the cards in that range are just ignored for card counting. You only want to add or subtract from the count with the other ranges of cards. Maybe that will remedy your original coding.

Dear @artistpw,
Good mornings,

Thank you for your help and kindness ,
i appreciate it, counting cards was a really hard thing to deal with,
kind regards,

Ivonne

Hi - you are very welcome. I love to see how the same problem is interpreted by others.