Basic javascript:counting cards

Basic javascript:counting cards
0

#1

i don’t find where is the probleme please need help:

function cc(card) {
  // Only change code below this line
  switch(card){
    case 2:
    case 3:
    case 4:
    case 5:
    case 6:
      count++;
      break;
    case 10:
    case "J":
    case "Q":
    case "A":
      count--;
      break;
  }
  if (count > 0){
    return count + " bet";
  } else {
    return count + " hold";
  }
  // Only change code above this line
}

#2

Look carefully at the words you are returning vs. the words the challenge wants you to return. “bet” is not the same as “Bet”.


#3

:grin: thank you but i have changed it and there is always the same probleme
bet to Bet
hold to Hold


#4

i found i haven’t wrote the case"k"


#5

thank you for your quick responce @RandellDawson


#6

Hello friends,
Decided to stick to this topic rathen than creating a similar one.

I have a similar solution of this Blackjack counting cards task. And it passes all the tests succesfully. Also I took the last piece of code and added console.log to it to see what it returns.

if (count > 0) {
console.log(count + " Bet");
return count + " Bet";
} else {
console.log(count + " Bet");
return count + " Hold";
}

and it returns as many outputs as many arguments we have for our function:
cc(2); cc(3); cc(4); cc(5); cc(6);
returns
1 Bet
2 Bet
3 Bet
4 Bet
5 Bet

Looks like we have 5 outputs instead of one. Of course we know that out of these 5 the last one is the one we need to pass the the test succesfully. The question is: how come that in order to pass the test only the final (and correct) output is taken into consideration? Why other 4 are ignored?

Hope it makes sense :slight_smile: