jeudi 7 juillet 2016

Given 2 positive int values, return the larger value that is in the range 10..20 inclusive, or return 0 if neither is in that range

My problem is that I can't seem to access the second else/if statement where I try to include a clause where if a number is still in range it should still return. The syntax is all correct, I was told my brackets are improperly placed but I can't fathom where or how.

var max1020=function(a, b) {
if ((a >= 10 && a <= 20) && (b >= 10 && b <= 20)) { 
      if (a > b) { //comparing my a and my b and returning greater
      return a;  
        } else if (b > a) {  
          return b;
    } else if ((a >= 10 && a <= 20) || (b >= 10 && b <= 20)) { 
        if (a >= 10 && a <=20) {
        return a;
        } else if (b >= 10 && b <=20) {
            return b;
        }
    } else 
        return 0;
    }
};

Aucun commentaire:

Enregistrer un commentaire