Counting Cards Code

Tell us what’s happening:
Everything works except "Cards Sequence 7, 8, 9 should return “0 Hold”.
Please I need help with and if there’s any problem with my code which is causing it not to work.
Thanks!

Your code so far

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

// Add/remove calls to test your function.
// Note: Only the last will display
cc(2); cc("J"); cc(); cc(5); cc(6);

Your browser information:

Your Browser User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:60.0) Gecko/20100101 Firefox/60.0.

Link to the challenge:
https://www.freecodecamp.org/challenges/counting-cards

okay thanks! But can you show me where within my code? is it with the switch statement?

My switch statement acts as something like a conditional to test the cards and to increase/decrease the count

Oooh okay! That means the problem lies within the if/else statement

Thanks for helping me to figure it out.

It now works :grin::+1:

okay, i’ll try that one too

hahaha… I think i’m stuck. Only one worked.

var count = 0;

function cc(card) {
  // Only change code below this line
 
 var firstCards = [2, 3, 4, 5,6];
 var secondCards = [7,8,9];
 var thirdCards = [10, "J","Q","K","A"];
  
  if (card == firstCards) {
    count++;
    return count + " Bet";
  } else if (card == secondCards) {
    count = 0;
  } else {
    count--;
    return count + " Hold";
  }
 
  return card;
  // Only change code above this line
}

// Add/remove calls to test your function.
// Note: Only the last will display
cc(2); cc(3); cc(4); cc(5); cc(6);

//The problem is here as far as I noticed. You should return conditionally and use "count " variable. You do not need to anything with “card” value except take function parameters.

if (count > 0) {
return count + " Bet";
}
else {
return count + " Hold";
}