Counting Cards, not receiving check mark

Tell us what’s happening:
I’m getting every checkmark except Cards Sequence 3, 7, Q, 8, A should return -1 Hold
I don’t see why I’m not getting this as it is set up the same as every other check mark. Mabey it’s something obvious like spelling but I have bene looking for awhile now at cant pinpoint the problem.

Your code so far


var count = 0;

function cc(card) {
  // Only change code below this line
  switch(card) {
      case 2, 3, 4, 5, 6: return "5 Bet";
      case 7, 8, 9: return "0 Hold";
      case 10, 'J', 'Q', 'K', 'A': return "-5 Hold";
      case 3, 7, 'Q', 8, 'A': return  "-1 Hold";
      case 2, 'J', 9, 2, 7: return "1 Bet";
      case 2, 2, 10: return "1 Bet";
      case 3, 2, 'A', 10, 'K': return "-1 Hold";
  }
  
  
  return "Change Me";
  // Only change code above this line
}

// Add/remove calls to test your function.
// Note: Only the last will display
cc(2); cc(3); cc(7); cc('K'); cc('A');

Your browser information:

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

Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/basic-javascript/counting-cards

switch(card) {
      case 2, 3, 4, 5, 6: return "5 Bet";
      case 7, 8, 9: return "0 Hold";
      case 10, 'J', 'Q', 'K', 'A': return "-5 Hold";
      case 3, 7, 'Q', 8, 'A': return  "-1 Hold";
      case 2, 'J', 9, 2, 7: return "1 Bet";
      case 2, 2, 10: return "1 Bet";
      case 3, 2, 'A', 10, 'K': return "-1 Hold";
  }

You are not supposed to hard code each of the tests in. You are supposed to tell it what to do to the count for each possibility. You’re also using the switch incorrectly. Here’s something I wrote up for someone else:

function isAVowel(letter) {
  let answer
  switch (letter.toLowerCase()) {
    case 'a':
    case 'e':
    case 'i':
    case 'o':
    case 'u':
      answer = "yes"
      break
    case 'y':
      answer = "sometimes"
      break
    default:
      answer = "no"
  }
  return answer
}

You need to do something similar, listing out the different cards and what action should be taken. I would suggest grouping cards 2-6 in one where you add 1 to count, then 10-‘A’ where you subtract one, and then just default to do nothing (7-9).

Does that make sense?

3 Likes

so based of what you said, my code is now this.

var count = 0;

function cc(card) {
// Only change code below this line
switch (card) {
case 2:
case 3:
case 4:
case 5:
case 6:
return (count + 1);
break;
case 10:
case ‘J’:
case ‘Q’:
case ‘K’:
case ‘A’:
return (count - 1);
break;
default:
(count + 0);
break;
}
if (count > 0) {return count + “Bet”}
else if (count <= 0) {return count + “Hold”}

// Only change code above this line
}

// Add/remove calls to test your function.
// Note: Only the last will display
cc(2); cc(3); cc(7); cc(‘K’); cc(‘A’);

I am still not receiving any check marks though. Whats the problem?

OK, you’re on the right track, a big improvement.

Consider the line:

return (count + 1);

You don’t want to return count+1 out of the function. You just want to increment count. Do you remember how to increment a variable? You definitely don’t want to return there.

(count + 0);
break;

You can omit these lines. “default” doesn’t need a break and you don’t want it to do anything so leave it blank. It’s good to have a default, but leave it blank.

if (count > 0) {return count + “Bet”}
else if (count <= 0) {return count + “Hold”}

Both of those messages need a space before the word.

And I’m assuming that those smart quotes (curly) are just a symptom of cut and paste.

But if I make those changes, it passes.

2 Likes

Thanks man, I find myself verry lost on the tests that make you find a solution to the problem without much guide, and you helped a lot. Cheers m8 and happy coding!