Basic JavaScript - Counting Cards

Tell us what’s happening:
Describe your issue in detail here.

Your code so far

hello i just try many times and switch the console log or the cc('k) but i still not vailable to get -5 hold or -1 hold for the secuences

let count = 0;

function cc(card) {
  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;
  }
   var holdbet = 'Hold'
  if (count > 0) {
    holdbet = 'Bet'
  }

  return count + " " + holdbet;



}

cc('A'); cc(10); cc('A'); cc(10); cc(10);
console.log(cc(-3));

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36

Challenge: Basic JavaScript - Counting Cards

Link to the challenge:

Uppercase vs lowercase matters here

1 Like

console.log(cc(10));
console.log(cc(‘J’));
console.log(cc(‘Q’));
console.log(cc(‘K’));
console.log(cc(‘A’));

-1 Hold
-2 Hold
-3 Hold
-3 Hold <---- ?
-4 Hold

1 Like

Thanks a lot11111111

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 7:
    case 8:
    case 9:
      count =0;
      break;
    case 10:
    case 'J':
    case 'Q':
    case 'K':
    case 'A':
      count--;
      break;
  }
  if(count <= 0) {
    return count+" Hold";
  }
  else {
    return count+" Bet";
  }
  // Only change code above this line
}

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

I am getting failure only for this scenario
Ideally it must be 0 according to me
But scenario says as it must return 1
Any idea ?

But

Do NOT reset count to 0 when value is 7, 8, or

Thank you it fixed the issue i kept it as it is as
count

1 Like