Why return doesn't work on the counting cards project

var count = 0;

function cc(card) {

  // Only change code below this line

switch (card) {

  case 2:

  case 3:

  case 4:

  case 5:

  case 6:

  return count++;

  break;

  case 7:

  case 8:

  case 9:

  return count + 0;

  break;

  case 10:

  case "J":

  case "Q":

  case "K":

  case "A":

  return count--;

  break;

}

if (count > 0) {

  return (count +" Bet");

} else {

  return (count + " Hold");

}

  // Only change code above this line

}

cc(2); cc(3); cc(7); cc('K'); cc('A');

it works, you are just not returning what it wants you to return

so how would it work then with return in it?

can you tell me what the challenge asks you to return?

Cards Sequence 2, 3, 4, 5, 6 should return 5 Bet

Cards Sequence 7, 8, 9 should return the string 0 Hold

Cards Sequence 10, J, Q, K, A should return the string -5 Hold

Cards Sequence 3, 7, Q, 8, A should return the string -1 Hold

Cards Sequence 2, J, 9, 2, 7 should return the string 1 Bet

Cards Sequence 2, 2, 10 should return the string 1 Bet

Cards Sequence 3, 2, A, 10, K should return the string -1 Hold

Ok, so the return statement should return only what is required. If you have return statements that return different things, those would make so that your function returns the wrong thing

so u can only use 1 return in a switch statement?

no, you can use how many you want.
But the return statement is used to determine the output of the function, in this case cc, so you need to use it in the right place inside the function, and that may be not inside a switch statement

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.