Need guidance on card counter

Need guidance on card counter
0

#1

I can get the increment / decrement to work but not properly unless I change the global count and I don’t believe that’s correct… Any insight would be appreciated.

var count = 0;

function cc(card) {
  if (card >= 2 || card <=6 ) {
    return count ++ + " Bet ";
  }
else if (card == "Q", "A", "J", "K"){
  return count -- + " Hold ";
}
else if (card == 10){
  return count -- + " Hold ";
}
else{
  return count;
}
  
  // Only change code above this line
}

// Add/remove calls to test your function.
// Note: Only the last will display
cc(10); cc("J"); cc("Q"); cc("K"); cc("A");

#2

I cleaned up your code.
You need to use triple backticks to post code to the forum.
See this post for details.

I’m on my phone so I can’t properly try it, but how about closing the space between count and the ++/--? Also try removing the space at the end of the string.

I’m not sure if card == "Q", "A", "J", "K" works. Try explicitly comparing each letter with card (you can use logical operators for this)


#3

great, thanks for the suggestions. I’ll give em’ a shot


#4

Hmm, I reduced the spacing and tried || logical operator and got the same result then tried all as separate else if statements and also achieved the same result?


var count = 0;

function cc(card) {
  if (card >= 2 || card <=6 ) {
    return count++ + " Bet";
}
else if (card == "Q"){
  return count-- + " Hold";
}
else if (card == "K"){
  return count-- + " Hold";
}
 else if (card == "J"){
  return count-- + " Hold";
}
else if (card == "A"){
  return count-- + " Hold";
}
else if (card == 10){
  return count-- + " Hold";
}
else{
  return count;
}
  
  // Only change code above this line
}

// Add/remove calls to test your function.
// Note: Only the last will display
cc(10); cc("J"); cc("A"); cc("K"); cc("J");


#5

You have misunderstood the assignment.

You should increment/decrement count depending on the card and then return ‘Bet’ or ‘Hold’ depending on the value of count.

Also if first statement of OR is true the remaining part is not checked.


#6

Just sat down to code after a long T-giving weekend. Thanks for the hints and for not giving me the answer! It now works as intended.

Thanks again.