Stumped! - Stuck on JavaScript Blackjack function [SOLVED]

Alright folks, currently in the Ask step of Read-Search-Ask. I’m creating a Blackjack function for the front-end JavaScript exercises using if/else if statements and I need guidance. I did see that the “Hint” page has a solution, but I’m determined to ask around and try a little harder to figure out the solutions myself, and figure out why my code is doing what it’s doing.

var count = 0;

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

cc(2); cc(2); cc(10);

What is currently happening, is that each argument passed adds 1 to the variable count, if we’re using zero-based indexing. I think something is wrong with my if statements, but I can’t tell. I’d love a different outlook for this one!

Thanks,

Julianna

Change this to if (card > 1 && card < 7 && count > 0)
Do the same for the other if conditions. You have to specify what is being compared in each “or”. For example if I wanted to test if card was 1 or 2 it would look like

if(card === 1 || card === 2) {
  //...do stuff
}

I’ve been staring at my if statements and thought something was wrong! Makes much more sense, thanks! I think now my trouble lies in adding the increment or decrement appropriately, but at least the 7 through 9 arguments are passing correctly.

Thanks! I’m trying to simplify the “if” statement right now for values 10, “J”, “Q”, “K” and “A”. I’m also trying to figure out a way to use increments or decrements on count before returning any values, but I’m not sure if that’s possible.

I’m not quite ready to see the answer, but I’ll return to this should I need it. Thank you!

Thanks every for all of your input and explanations. Stepping away from this problem for a few hours, reading everyone’s code and reviewing the if/else basics helped immensely with figuring out what was wrong with my original function. I’m going to try to find some similar problems I can practice until i can really get the swing of these statements. Here is my final code:

var count = 0;

function cc(card) {
  var result = "";
    if (card >= 2 && card <= 6) {
      count++;
      } else if (card === 10 || card === "J" || card === "Q" || card === "K" || card === "A") {
      count--;
      }
    if (count <= 0) {
      result = count + " Hold";
    } else {
      result = count + " Bet";
    }
  return result;
}