Basic JavaScript - Counting Cards

Tell us what’s happening:
Really stuck on this one. All the previous solutions seem to not be updated. For instance, for the first one Cards Sequence 2, 3, 4, 5, 6 should return the string 5 Bet. I tried before to write case 2 (all the way to 6) then return ‘5 Bet’ and then break. It shown it was correct, and I did it for the others too until I got to the ones where it had either the same numbers or letters. Then it stopped working. I had to erase that solution when I remembered the return value isn’t supposed to be in the switch statement. Now I’m completely stuck on this problem. Any help is much appearicated.

Your code so far

let count = 0;

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



}

  return "Change Me";
  // Only change code above this line
}

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_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/109.0.0.0 Safari/537.36

Challenge: Basic JavaScript - Counting Cards

Link to the challenge:

1 Like

i think you probably misunderstand the game.
For cards 2, 3, 4, 5, 6 the card changes by +1,
for cards J, Q, K, A, 10 the card changes by -1,
For cards 7, 8, 9 the card doesn’t not change

In addition, if the current count based on the above is positive then bet, and when the current count is zero or negative then hold

This is what I did the first time around, but it didn’t allow me to go through. I think there are other things that have been added to the lesson. This is my current code.

if (card === 2 || card === 3 || card === 4 || card === 5 || card === 6){
return ‘5 Bet’;
} else if (card === 7 || card === 8 || card === 9){
return “0 Hold”;
} else if (card === 10 || card === “J” || card === “Q” || card === “K” || card === “A”){
return “-5 Hold”;

} else if (card === 2 || card === “J” || card === 9 || card === 2 || card === 7){
return “1 Bet”;
}

Things like return a string 1 Bet etc have been added to the lesson.

switch(card){
  case 2:
  case 3:
  case 4:
  case 5:
  case 6:
  count++;
  break;
  case 10:
  case "J":
  case "Q":
  case "K":
  case "A":
  count--;
  break;
   if (count > 0){
    return count + " Bet"
   } else {
     return count + " Hold"
   }

I think this is the solution to what you’ve mentioned but it doesn’t work on this lesson anymore.

typo supposed to be count--

When posting code, please insert it between backticks to make it more readable.
You can do this by clicking on the </> and pasting your code where indicated.

Aside from the decrement error mentioned in the previous response, your code (above) is correct except that you haven’t closed off your switch statement properly (before your conditional statement).

Thanks for the tip! But it’s not allowing me to move past to the next lesson. It has extra things in the lesson like this:

  • Waiting:Cards Sequence 2, 3, 4, 5, 6 should return the string 5 Bet

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

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

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

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

  • Waiting:Cards Sequence 2, 2, 10 should return the string 1 Bet

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

what is your code after you have modified it? Post it here

none. I don’t know how to go about it. That’s why I posted the question.

The code you posted here is almost correct only slightly wrong

However the correction is here:

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