Card count - code passes but doesn't seem to work in all cases

Other forum threads on the card counting challenge were really helpful, I feel like I got to a good understanding of how to arrive at my solution, but it doesn’t seem to give the correct outputs for all the examples given.

Here is my solution:

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 += 1;
  case 7:
  case 8:
  case 9:
  count += 0;
  case 10:
  case 'J':
  case 'Q':
  case 'K':
  case 'A':
  count -= 1;

if (count > 0) {
  return count + " Bet";
  return count + " Hold";
  // Only change code above this line

console.log(cc(10, 'J', 'Q', 'K', 'A'));
cc(2); cc(3); cc(7); cc('K'); cc('A');

This solution is currently passing the lesson. However…

In the example I’ve tried to log, the lesson says “Cards Sequence 10, J, Q, K, A should return the string -5 Hold”, but my log displays “-1 Hold” instead. In fact, none of the negative count values (10, J, Q, K, A) submitted seem to be returning values below -1, which makes me think something is either wrong with the way I’m testing it in the console or with the function count -= 1?

The calls to the function only take one argument at a time

1 Like

got it, I thought it might be something like that! So is there a way to test a sequence like in the example given?

hold on, I think I figured it out?


this does arrive at -5 Hold. Not as straightforward as I imagined, but I guess it works!

1 Like

You could definitely write the function in such a way to take one or more arguments and be able to write: cc(2, 3, 7, 'K', 'A'); instead of cc(2); cc(3); cc(7); cc('K'); cc('A'); Once you get a bit more knowledge of JavaScript, you should come back and try to implement such a function for this challenge.

1 Like

ooh thank you for the idea! I think that was where I was initially coming from, which made my first attempts at coding the solution a mess. It makes sense there are other ways to write the function that are a bit more advanced - I’ll put a bookmark in this challenge then.