mardi 10 décembre 2019

Why does if else statement not work the same way as else if statement?

I am trying to put a cards counting game together. There is multiple ways to write this piece of code, but the thing that makes me think is what the difference is between those to code samples? The first piece of code works fine, but the second gives me undefined.

  if (count > 0) {
       var betHigher = "Bet Higher";
       return betHigher;

   } else {
       count < 0;
       var holdbet = " hold ";
       return holdbet + "" + count;

   }

This gives me undefined. Why is that?


    if (count > 0) {
        var betHigher = "Bet higher";
        return betHigher;

    } else if (count < 0) {
        var holdbet = " hold";
        return holdbet;
    }

}

Aucun commentaire:

Enregistrer un commentaire