Can u please send me help in counting card

Tell us what’s happening:

Your code so far

var count = 0;

function cc(card) {
  // Only change code below this line
  
  
  var val;
  var finalcount=0;
  for (var i = 0; i < arguments.length; i++) {
   
    val= Number(arguments[i]);
  
  
  if(val==2 || val==3 || val==4 || val==5 || val==6 )
    {
      count=1;
    }
  else if(val==10 || val=='J'|| val=='Q' || val=='K' || val=='A')
    {
      count= -1;
    }
  else 
    {
      count=0;
    }
    
    if(count>0)
      {
       finalcount += count;
 
      }
    else
      {
        finalcount -= count;
      }
    
    
  
  
  } 
  if (finalcount > 0)
        {
            
          return finalcount  +" " + "Bet";
        }
        else
         {
             
         return  finalcount +" "  + "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');
//cc(2,3,4,5,6);
cc(10,'J','Q','K','A');

Your browser information:

Your Browser User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36.

Link to the challenge:
https://www.freecodecamp.org/challenges/counting-cards

I don’t think you can put all of the card inputs in a single call to cc. You have to call them one by one (ala the first commented code at the bottom). This makes the finalcount variable unnecessary, since you’ll be dealing with the global count variable for every call.

1 Like

I did it first .but that code did not work .thats why I put all the things

Tell us what’s happening:

Your code so far



function cc(card) {
  // Only change code below this line
  var count ;
  
  if(card==2 || card==3 || card==4 || card==5 || card==6 )
    {
      count=1;
     

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

Your Browser User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36.

Link to the challenge:
https://www.freecodecamp.org/challenges/counting-cards