(Counting Cards) Below is my code.Need Some help to findout where i have gone wromg

Tell us what’s happening:
This worked for me and I passed the challenge.Thanks

Your code so far

var count = 0;

function cc(card) {
  // Only change code below this line
      
    if (card>1 && card<7){
      
    count++;
    
    }else if (card>7 && card<10)
    {

      count=count+0;

    }
    else if (card == 10 || (card >= 'A' && card <= 'Q')){
    
      count--;
      
    }


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

}
// Add/remove calls to test your function.
// Note: Only the last will display
cc(2); cc(2); cc(10); cc(0); cc(0);
//console.log(cc('J'));

Why are you changing the count by 5, it should be by one. Also, after you get the card and modify the count variable, before you return the result, you should check the number in the variable and return based on that. Effects are cumulative, you don’t return based only on the current card, but based on all the previous ones as well. The previous ones + the current one are captured in the count variable, so you need to revise your logic.

1 Like
This Worked out for me and i passed the challenge
var count = 0;

function cc(card) {
  // Only change code below this line
      
    if (card>1 && card<7){
      
    count++;
    
    }else if (card>7 && card<10)
    {

      count=count+0;

    }
    else if (card == 10 || (card >= 'A' && card <= 'Q')){
    
      count--;
      
    }


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

}
// Add/remove calls to test your function.
// Note: Only the last will display
cc(2); cc(2); cc(10); cc(0); cc(0);
//console.log(cc('J'));