Counting Cards game

Counting Cards game
0

#1

Tell us what’s happening:
please help, stuck and confused.CAN SOMEONE HELP KNOW WHATS WRONG WITH MY CODE PLEASE?

Your code so far


var count = 0;

function cc(card) {
  // Only change code below this line
  if (card == 2 || card == 3 || card == 4 || card == 5 || card == 6) {
    if ((card == 2 || card == 3 || card == 4 || card == 5 || card == 6)) { return "5 Bet"}
        else {
  ++count;
    return count + " Bet";
        }
  }
    
   else  if (card ==  7 || card == 8 || card == 9) {
      
      count = count + 0;
     return count + " Hold";
    
    }
  else  if ( card==2|| card==2|| card==10){
 if ((card==2||card =="J"||card==9||card==2||card==7)){
     return "1 Bet";
   }
   }
   else if ( card == 3||card== 2||card== "A"||card==10||card=="K"){
     f ((card == 3||card== 2||card== "A"||card==10||card=="K"))
     return "-1 Hold" }
     
   }
     if (  card == 10 || card == "J" || card == "Q" || card ==  "K" || card == "A") { 
      if ((card == 10 || card == "J" ||  card == "Q" || card == "K" || card == "A")) { return "-5 Hold"}
       


     else if (card == 3 || card == 7 || card == "Q" || card ==  8 || card == "A"){
 
 
  return "-1  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/66.0.3359.181 Safari/537.36.

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


#2

Your solution should be adding and subtracting from count based on the card value. Then, based on the count value (not the card value), you should return the count concatenated with either " Bet" or " Hold". Your current logic is actually basing the " Bet" and " Hold" part based on the card values, which is incorrect.

Looking strictly at your code for card values of 7, 8, or 9 (below), you can see the fault in your logic.

   else  if (card ==  7 || card == 8 || card == 9) {
      
      count = count + 0;
     return count + " Hold";
    
    }

Let’s say the card value is 8, so your code above adds 0 to the current value of count and then returns count + " Hold". The problem is, what if the current value of count was 5, your code would return “5 Hold”, when instead it should return “5 Bet”. You need to separate the logic of incrementing and decrementing the count value (which is based only on the card value) from what actually gets returned (which is based on the value of count and not the card value).