JS: Card Counting, help debugging - Why can I not identify 10?

Tell us what’s happening: I seem to be having trouble passing a card equaling ten through my script. I have tried using strict (===) and non-strict (==) comparisons, but neither seem to work for having the script recognize that the ten should decrease overall count.

All other parts of the script appear to be working as intended.

Help identifying the issue would be appreciated! Thanks!

Your code so far


var count = 0;
var decision = 0;

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

// Add/remove calls to test your function.
// Note: Only the last will display
cc(10); cc("J"); cc("Q"); cc("K"); cc("A"); 

console.log(count);

**Your browser information:**

User Agent is: <code>Mozilla/5.0 (X11; CrOS x86_64 12371.75.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/77.0.3865.105 Safari/537.36</code>.

**Challenge:** Counting Cards

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

what happens to make you say that it doesn’t work?

You made a mistake in your logic

What happens when 10 hits this?
else if (card > 6 || card < 10)

1 Like

@ilenia - the console.log results for passing a ten through the function result in a zero rather than a -1.

@broregard - it shouldn’t so anything? That logic statement should only apply to 7, 8 and 9. Is there something I am missing on it…?

Thank you to everyone that responded! :smiling_face_with_three_hearts: I understand what went wrong now and it was such an easy fix!