Counting Cards - If statement issue?

Hey guys! I got switch statements working but I can’t get these if statements working. I have a feeling that my 10 through A line isn’t working but I don’t know why? Thanks for any help.

var count = 0;

function cc(card) {
  // Only change code below this line
  if (card >= 2 && card <= 6) 
  else if (card == 10 || card == 'J' || card == 'Q' || card == 'K' || card == 'A') 
  else if (count <= 0) 
  return count + " Hold";
  else (count > 0) 
  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 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.98 Safari/537.36.

else if (count <= 0) ype or paste code here

Why is this an else if? When does it execute?

1 Like

For some reason I thought if you wanted more if statements you had to chain else ifs. Is just a plain “if” statement fine to use?

edit: changing the else if to if on the count line fixed it! I understand now. Thank you Ariel!

Your if statements are chained off of different variables. One pair of if statements goes off of the card, the other goes off the count.

So, for example, if a statement passes true for either of the first two if statements, then the third statement will never hit.

If you could link or tell more about the problem, I could help further. But think of it like this…

let x=0

if (x>0)
console.log(“x is greater than 0”);
else if (x==0)
console.log(“x is 0”);
else if ( /////////anything below here won’t happen since the second statement is true

1 Like

I actually fixed and complete the whole thing just by changing the else if to if. Thanks for that solution too!!!