Javascript Counting cards

Javascript Counting cards
0

#1

Hi!
I’m having some trouble with my code, can someone help me with what I’m doing wrong?

var count = 0;

function cc(card) {
  // Only change code below this line
 if (card == 2 || card == 3 || card == 4 || card == 5 || card == 6) {
   count ++;
 } else if (card == 7 || card == 8 || card == 9) {
   count;
    } else if (card == 10 || card == 'J' || card == 'Q' || card == 'K' || card == 'A') {
   count --;
 }
    
  if (count <= 0) {
    return count + 'Hold';
  }
  else {
    return count + 'Bet';
  }
  // 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');```


Challenge link: https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/basic-javascript/counting-cards

#2

What exactly is it doing or not doing?

One of the biggest gotchas with this one, and I can see it bit you, is that you’re currently returning, for example 4Hold or -2Bet – is that the response it wants?


#3

And out of curiousity, what is the point of this branch of the if statement? It doesn’t do anything, doesn’t change anything… I’d get rid of it, myself.


#4

You’re missing spaces in your output.


#5

Lol and here I was trying to be subtle…


#7

Got it!

Thanks you very much! :slight_smile: