Basic JavaScript: Counting Cards [Help!]

I have seen multiple solutions using "switch " and some "else if’ but I really want to make my code work. Would you mind taking a look? Thank you!

var count = 0;

function cc(card) {
  // Only change code below this line

 if (card <=  6 && card <= 2) {
  count  = count + 1 ;

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

 return count + "Hold"

  }

  else if ( card = 10  ||  'J'  || 'Q ' || 'K' || 'A') {
    count = count - 1 ;
    return count  + "Hold"
  }
 
  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');

randelldawson,

Thank you for your swift response. Your insights are absolutely helpful.

Tell us what’s happening:
I have been tackling this challenge for a few hours and I can’t get why it does not accept the following conditions:

Cards Sequence 10, J, Q, K, A should return -5 Hold
Cards Sequence 3, 7, Q, 8, A should return -1 Hold
Cards Sequence 3, 2, A, 10, K should return -1 Hold

Your code so far


var count = 0;
var answer = ''

function cc(card) {
  // Only change code below this line

 if (card >=2 && card <=6)  {
  count  = count + 1 ;

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

  }

  else if ( card == 10||'J'||'Q'||'K'||'A') {
    count = count - 1 ;
  }
 
 if (count > 0) {
answer = (count) + " Bet";

} else if (count === 0) {
answer = (count) + " Hold";
}
else if (count <= 0) {
answer = (count) + 'Hold';
}

return answer;
  // 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");

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.99 Safari/537.36.

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

have you tried adding a bunch of console.log and running your code to see if you are getting what you expect at different points in the program? That’s what I would be doing…

Thank you. I will definitely try your suggestion.

ok, just fyi, i noticed you forgot a space for one of the Hold return strings…

Thank you for that observation.