vendredi 27 avril 2018

Getting "undefined" result when using the logical operator "&&" in a JavaScript If..Else statement

The code is for selecting the federal poverty level (var fpl) percentage category base on the income (var income). When I run this script, my result is "undefined" when I use the && logic operator. If I use the || logic operator, I get the wrong and same answer - "101-185%" - no matter what number I use for var income.

<p id="demo"></p>

<script>
  function FPL() {   

    var income = '4200.00';
    var fs = '1';

        var fpl;  
        if(fs == '1') {
            if(income < '1022.00')
               fpl = "0-100%";  
            if (income > '1022.00' && income < '1882.00') 
               fpl = "101-185%";   
            if (result3 > '1882.00' && income < '2033.00') 
               fpl = "186%-200%";
            if (income < '2033.00')
               fpl ="'201% & Over";

            return fpl;                

        }             

        result6 = 'Federal Poverty Level: ' + fpl;

        document.getElementById("demo").innerHTML = result6;
 }   

</script>

Are the logic operators in an Else..If statement used differently in JavasScript?

Aucun commentaire:

Enregistrer un commentaire