Counting Cards gone wrong :(

Tell us what’s happening:

Your code so far


var count = 0;

function cc(card) {
  // Only change code below this line
 if(card<7){card =+1;}
 else if(card>6){card =+0;}
 else switch(card){
   case "10":
   case "J":
   case "Q":
   case "K":
   case "A":
   card =-1;
 }
 if(card%0){
   return "Bet";
 }
 else return "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/67.0.3396.99 Safari/537.36.

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

OK,

There are a lot of little problems here.

First of all, on lines like:

 if(card<7){card =+1;}

There is no operator =+ - you mean ‘+=’

Also, on the line:

else if(card>6){card =+0;}

even if the operator was right, it is pointless to add 0.

   case "10":

That card will be sent as a number, not a string.

if(card%0){

I’m not sure what this is checking. mathematically. You want to check if count is greater than 0.

 if(card%0){
   return "Bet";
 }
 else return "Hold";
}

Read the instructions more carefully, it’s supposed to be the count followed by a space and then the message.

OK, so your “logic” is a little messy, choose between if/else or switch. You just learned about switch and it makes the code more intuitive here, so that is a good idea.

Remember that you can have multiple cases. And you also have a default case for anything left over. Consider the following function:

function isAVowel(letter) {
  let answer
  switch (letter.toLowerCase()) {
    case 'a':
    case 'e':
    case 'i':
    case 'o':
    case 'u':
      answer = "yes"
      break
    case 'y':
      answer = "sometimes"
      break
    default:
      answer = "no"
  }
  return answer
}

Your structure should look something like this. Have cases for 2-6 that add to count, for 10-“A” that subtract, and a default that does nothing.

If you make those changes you should pass. Let us know if you get stuck or something needs more explaining.

1 Like