Can't seem to pass pliz help!

Tell us what’s happening:

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 6.3; WOW64; rv:63.0) Gecko/20100101 Firefox/63.0.

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

@chunguz Just curious, why did you decide to write the case statements to match the tests? I think part of the point of this challenge involves incrementing and decrementing.

@camper can u pliz help me solve this at least tell me what am doing wrong. I don’t understand the point of this challenge and besides what does incrementing and decrementing mean??

@chunguz Incrementing means to add 1 to something and decrementing means to subtract 1 from something. Here’s the text from the challenge:

You will write a card counting function. It will receive a card parameter, which can be a number or a string, and increment or decrement the global count variable according to the card’s value (see table). The function will then return a string with the current count and the string Bet if the count is positive, or Hold if the count is zero or negative. The current count and the player’s decision ( Bet or Hold ) should be separated by a single space.

What other questions do you have about that text?

Hi :slight_smile:

You need to refer to this course: Multiple Identical Options in Switch Statements

With the switch statement, you’ll update your var count depending, and then if the result is positive you’ll display “X Bet” else if the result is 0 or negative you’ll display “X Hold”.

Try to correct, and come back if necessary! :slight_smile:

@mangasource Hi:smiley:
all the cases are correct except for case 3,7,‘Q’,8,‘A’: return “-1 Hold”; I have tried everything in my power I can’t seem to pass this case to pass the entire test so can you pliz tell me what am doing wrong am so frustrated:weary:

Hi :slight_smile:

Can you show us the code you writed so far? :slight_smile:

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";
  }

It looks like you’ve misunderstood that the function cc evaluates cards only one at a time. The function itself only needs to carry out the following actions:

  1. increment, decrement, or do nothing to the value of count
  2. return a string that contains the count followed by Bet or Hold depending on count’s value
1 Like

I think you have to read the course Multiple Identical Options in Switch Statements again, cause switch statement does’nt work like that :wink:

case 2,3,4,5,6:return "5 Bet"; Not the good way.
Use something like that:

case 2:
case 3:
case 4:
case 5:
case 6:
  [YOUR ACTION];

thanx guys I finally passed the test after so much struggle thanx for all your advises:relieved::joy:

1 Like