Counting Cards, why doesn't this work?!

Tell us what’s happening:
I’ve completed the exercise using the switch statement and then went back to try it out using an if statement.
I don’t understand where I’m going wrong here. Is anyone able to help?

Your code so far


var count = 0;

function cc(card) {
  // Only change code below this line
  if(card > 1 && card < 7){
    count++;
  }else if(card > 6 && card < 10){
    card += 0;
  }else{
    card--;
  }
  if(count < 1){
    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');

Your browser information:

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

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

Look at the second and third blocks of code in the first if/elses

2 Likes

ahhh, I used card instead of count. Thank you!

1 Like