Counting Cards - if/else causing issue

Tell us what’s happening:

Why does the challenge NOT pass for “case 7,8,9” when I use the curly braces on my if/else the why I have it commented out, but it DOES pass the way it is?

Your code so far


var count = 0;

function cc(card) {
  // Only change code below this line
  switch(card){
    case 2:
    case 3:
    case 4:
    case 5:
    case 6:
    count += 1;
    break;

    case 7:
    case 8:
    case 9:
    count += 0;
    break;

    case 10:
    case 'J':
    case 'Q':
    case 'K':
    case 'A':
    count -= 1;
    break;
  }
  if (count>0){
    return count + " Bet";
  }
  else return count + " Hold";
  
  /*if(card > 0){
    return count + " Bet";
  }else{
    return count + " Hold";
  }
  */
  
  // 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_13_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.87 Safari/537.36.

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

But why would it only affect the “7,8,9”? All the other tests pass.

Sorry i misunderstood the question. There is nothing wrong with the commented out if that i can see. But for the switch the count+=0 is redundant as you only need to execute the break statement for 7/8/9.

What error do you see when you use the braces in the else?

It just wont pass the test for some reason. It doesn’t tell me why and for the life of me I couldn’t figure it out. I saw that someone else solved the challenge by not having the curly braces around the “else return” and it passed. I just don’t understand why that is.

I’m going to try it now (your code). Was just waiting to get to a real computer (not mobile).

ok, so here’s what I tried (and which worked perfect!):

I removed the line for count+=0;
and then I added braces to the code you have that is not commented out.
Worked perfect!

here’s the full thing:

// Only change code below this line
  switch(card){
    case 2:
    case 3:
    case 4:
    case 5:
    case 6:
    count += 1;
    break;

    case 7:
    case 8:
    case 9:
    break;

    case 10:
    case 'J':
    case 'Q':
    case 'K':
    case 'A':
    count -= 1;
    break;
  }
  if (count>0){
    return count + " Bet";
  } 
  else {
    return count + " Hold";
  }
    
  
  return "Change Me";
  // Only change code above this line