Why does this not work? ||

Tell us what’s happening:

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


// Only change code above this line
}

cc(2); cc(3); cc(7); cc('K'); cc('A');

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.130 Safari/537.36.

Challenge: Counting Cards

Link to the challenge:

Could you give this a try… notice the slight change… Also keep in mind that Hold should be when count is zero or a negative number… good luck!

var count = 0;

function cc(card) {
  if (card === 2 || card === 3 || card === 4 || card === 5 || card === 6) {
    count++;
    if (count > 0) {
      return count + " Bet";
    } else if (count < 0) {
      return count + " Hold";
    }
  } else if (card === 10 || card === "J" || card === "Q" || card === "K" || card === "A") {
    count--;
    if (count > 0) {
      return count + " Bet";
    } else if (count < 0) {
      return count + " Hold";
    }
  } else if (card === 7 || card === 8 || card === 9)  {
    return count + " Hold";
  }
}
1 Like

you can’t put conditions for an else statement, make it an if else or remove condition

are you sure that with cards 7,8 or 9 you can only hold?

try to avoid so much repeated code, can you having so many if/else that check for the same thing? can you have only one?

So an else statement should only be the following with no conditions?

:

else {

}

noted

yes, that’s how you write an else statement, and it can be o my the last element in a sequence of if/else if/else statements, and there can be only one