Basic JavaScript - Counting Cards

Tell us what’s happening:

Hello, i’m feeling somewhat lost about the solution to this exercise - tests mention that function should return a string, but as we call same function multiple times … we get a number of strings, same with calling our hand as ‘card sequence’, as it’s only a ‘sequence’ in words.

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:
      count++;
      break;
    case 10:
    case 'J':
    case 'Q':
    case 'K':
    case 'A':
      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');

Challenge Information:

Basic JavaScript - Counting Cards

Each function call returns a string. However, because this function depends on the global count variable, result for the same argument can change. Take a look:

console.log(cc(2));   // 1 bet
console.log(cc(2));   // 2 bet
console.log(cc(2));   // 3 bet
1 Like

I know, i’m talking about how it returns a string for every card, rather than once per cards sequence.
I’m not exactly complaining, that’s just what ‘tests’ seem to imply.

Hmm, I’m not sure I understand your question then. Could you try to rephrase it a bit?

Not a question, i just felt a bit weird about the solution, compared to what’s asked in the “tests” section.

the function is called multiple times, that doesn’t change that one function call returns a string

Yes, though every function call returns a string, so while

Cards Sequence 2, 3, 4, 5, 6 should return the string “5 Bet”

returns the required string, it’s not the only string.

True, it’s not the only string, but the last function wouldn’t return that string without the other 4 being called before

You can submit an issue to discuss this, but note that the legacy stuff is not maintened by staff anymore, it has to go completely through volunteers

1 Like

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