Counting cards. Help with my code please

var answer;
var count = 0;

function cc(card) {
  // Only change code below this line
  if (card <= 6) {
    count --;
  } else if (card <= 9) {
    count += 0;
  } else {
    count ++;
  }
  
  if (count > 0) {
    amswer = count + " Bet";
  } else {
  
  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(2); cc(3); cc(7); cc('K'); cc('A');

Why does this not work? Not sure what I am missing. A little help please.

I cleaned up your code.
You need to use triple backticks to post code to the forum.
See this post for details.

As to your problem,

  1. Double check that your counting logic meets the challenge requirements. Hint: it does not.
  2. Make sure all of your variables are spelled correctly.
1 Like

A much easier way to write this would be with a switch statement.

Thanks for the help. Don’t know how I missed that. Fixed the spelling and counting and it works now.

1 Like