Basic JavaScript: Counting Cards help needed

I want to know why my solution doesn’t work with 2 switch statements? I had to replace the 2nd switch with if statements for it to work. Can someone explain please?

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++;      
      break;
    case 7:
    case 8:
    case 9:
      count += 0;
      break;
    case 10:
    case 'J':
    case 'Q':
    case 'K':
    case 'A':
      count--;
      break;
  }

  switch (count) {
    case count > 0:
      return count + " Bet";
    case count <= 0:
      return count + " Held";
  }
 
    if (count > 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(4); cc(5); cc(6);

Switch cases matches against the expression, they are not a way to evaluate expressions:

switch(expression) {
  case value
}

/* in your case you are inverting */
switch(count) {
  case (count > 0) // it's an expression, not a value
}

hope it helps :+1:

1 Like

Yes, but what’s the point of it?

I know that technically works, but the real question is why would you write a constant condition.
Looks either like poor design or dev code not ready for production. :laughing: