Counting Cards Stuck

Counting Cards Stuck
0.0 0

#1

Tell us what’s happening:

why its not Completing

Cards Sequence 2, J, 9, 2, 7 should return 1 Bet

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+= 1;
    break;

    case 7:
    case 8:
    case 9:
    count= 0;
    break;

    case 10:
    case "J":
    case "Q":
    case "K":
    case "A":
    count-= 1;
    break;
  }
  
  if( count > 0 ) {
return count + " Bet";
}
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(2); cc(7); cc("J"); cc(2);

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.87 Safari/537.36.

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


#2

Hi,

Your problem is with this line:

count = 0;

I don’t want to just give you the answer as that’s not going to help you understand it.

Have a think about what this line is doing and then compare it to what you are doing to the count variable for other cases. Then have a re-read of the instructions to see what you should change this line to.

Hope this helps to point you in the right direction :slight_smile:


#3

Thanx for bringing my attention to that … :slight_smile: