Whats wrong With Counting Cards

Whats wrong With Counting Cards
0

#1

Tell us what’s happening:

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
  var count = 0;
  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 == 10 || card == "J" || card == "Q" || card ==  "K" || card == "A") { 
      if ((card == 10 || card == "J" ||  card == "Q" || card == "K" || card == "A")) { return "-5 Bet"}
        else {
      
      --count;
      return count + " Hold";
        }
    
    }
    
    
      
 
  
  
  return count;
  // Only change code above this line
}

// Add/remove calls to test your function.
// Note: Only the last will display
cc(2); cc(3); cc(4); cc(5); cc(6);

Your browser information:

Your Browser User Agent is: Mozilla/5.0 (X11; Ubuntu; Linux i686; rv:50.0) Gecko/20100101 Firefox/50.0.

Link to the challenge:


#2

@magalle,
just running your code and console.log the results, it seems that you are returning 5 Bet for everything.
Another thing is that you have a global count variable and a local one (with the same name). You are not supposed to have both. And initializing the local count variable everytime the cc method is called, is also bad since you want the count variable to store the cards seen from previous runs.

I would suggest that you start this challenge from the beginning again with these things in mind. I would also recommend reading the instructions again.

Good luck.