Counting cards challenge problem

Hello,

So i was on the counting cards challenge, and i wrote the following code according to the challenge, but i get output incorrect for two inputs
1 : 2,J,9,2,7
2: 2,2,10

Here’s my code

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;

    return count + " Bet";

    break;

  case 7:

  case 8:

  case 9:

    count += 0;

    return count + " Hold";

    break;

  case 10:

  case "J":

  case "Q":

  case "K":

  case "A":

    count -= 1;

    return count + " Hold";

    break;

}

  return "Change Me";

  // Only change code above this line

}

cc(2);cc("J");cc(9);cc(2);cc(7);

Please guide me as what is incorrect.

this one will make count be +1+1-1, so total 1, and for positive value you have to Bet, but your code returns 1 Hold

1 Like

I’ve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.

You can also use the “preformatted text” tool in the editor (</>) to add backticks around text.

See this post to find the backtick on your keyboard.
Note: Backticks (`) are not single quotes (’).

Got it. Thank you :slight_smile:

Ohhh! Got it. I’ll have to separate that count and display stuff

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