Counting Cards: I'm stuck and would like guidance for where I'm deficient

Tell us what’s happening:

I’ve read through several of the posts on this particular puzzle and I’m just not getting it. If you would please look at my code below and tell me what I’m overlooking because I’m sure I am but I can’t push any farther. Also, I’ve tried switch to solve it, but I’ve come to the same issue. I’m stuck. A guiding/gesturing/correcting hand in the area of both possible syntax for solving this problem would be greatly appreciated.

Thank you

Your code so far


var count = 0;

function cc(card) {
  // Only change code below this line
  if (card <= 6) {
    count++;
  }
  else (card >= 10); {
    count--;
  }

if (card = count++) {
  return "Bet";
} else {
    return "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');

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

You’re very close, but you’ve missed a slight detail in the instructions, as well as something important about the high value cards

Firstly:

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 above has nothing to do with the current card value, also not sure why you’ve incremented it there either

Secondly, the high value cards aren’t passed as numbers, they’re passed as strings, e.g. K for king (which you assumed would be 13)

Okay. I feel as if this might be even worse, but I’ve attempted to follow what I think you were hinting at in terms of the “high value cards”. I have attempted to account for the dealing of 5 cards of low suit (card <=6) and (count+5) as indicating a positive integer and, therefore, that the player should “Bet”. And vice-versa for the dealing of 5 high cards (card >9) and (count -5) that indicate a “Hold”.

However, it feels as if I’m not addressing a deadly important issue or aspect of the function. I’m not sure if this is [1]to do with my syntax or if [2] I’m neglecting to include an element or item in my function.

var count = 0;
function cc(card) {
if (card <=6)  {
(count + 5) = 1;
} else (card >9) {
(count-5)  = -1;
}

if (card+5) {
return "Bet";
} else {
return "Hold";
}


return "Change me";

Tell us what’s happening:
I created a post trying to understand how to solve counting cards with if/else syntax (haven’t managed yet) and I wanted to ask for advice in trying to solve this problem in switch syntax. Would someone mind telling me if I am on the right track at all?

Thanks.

Your code so far


var count = 0;

function cc(card) {
  switch(card) {
    case 2: 
    case 3: 
    case 4: 
    case 5: 
    case 6:
    count += 1;
    break;
    case 10:
    case "J":
    case "Q":
    case "K":
    case "A":
    count -= 1;
    break;
  }

  if (card <=6) {
    card<=6 + 5;
    return "Bet";
  } else {
    return "Hold";
  }
  return "Change me";
}
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/64.0.3282.140 Safari/537.36 Edge/17.17134.

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

I altered the end of the switch sequence:

if (cc(card = count > 0)) {
return “Bet”;
} else {
return “Hold”;
}

The cc function includes the cases of all the cards which still allow for a return of “Bet”. This doesn’t past the test, so I’m still missing something though.

Is this what you were referring to in regard to concatenation?

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

Is this what you were referring too?

if(count>0){return count+“Bet”;}

Okay. I understand.
if(count>0){return count + “Bet”;}

Although FCC is still not passing me. It says “//running test”, which I assume may have something to do with connection speed on my part because I believe I have passed.

Thanks @camperextraordinaire

Tell us what’s happening:

Your code so far


var count = 0;

function cc(card){
 switch(card){
   case 2:
   case 3:
   case 4:
   case 5:
   case 6:
   count +=1;
   break;
   case 10:
   case 'J':
   case 'Q':
   case 'K':
   case 'A':
   count -=1;
   break;
 }
 if(count>0){
   return count + 'Bet';
 }
 }
  cc(2);

This is what I have so far. It’s not testing out, but I’m not sure why. Logically, it seems that the return would generate the appropriate data and I believe I have addressed the spacing problem, but perhaps I misunderstood what you were hinting at.

What am I missing?

 if(count>0){
   return (count + 'Bet');
 }
 if(count<0){
   return (count + 'Hold');
 }