Прежде всего, давайте проверим ваш код, потому что у вас есть ошибки, я добавлю комментарии о том, где они находятся.
примечание: также будьте осторожны при сравнении строк, например "400" > "100000"
вернет true
. поэтому, если вы хотите сравнить значения, проанализируйте их перед сравнением.
function FPL() {
var income = '4200.00';
var fs = '1';
//set a default value here to fpl or inside an else.
var fpl;
if(fs == '1') {
//on all these ifs, you dont have an else, then if your income doesnt fill your criteria, it will be undefined.
if(income < '1022.00')
fpl = "0-100%";
if (income > '1022.00' && income < '1882.00')
fpl = "101-185%";
if (result3 > '1882.00' && income < '2033.00') //result3 doesnt even exist, this will throw an error.
fpl = "186%-200%";
if (income < '2033.00')
fpl ="'201% & Over";
// if you return here, how do you expect the following code to execute?
// you just needed to continue the workflow
return fpl;
}
//this code is never executed, unless fs is different than 1 (but it is hardcoded)
result6 = 'Federal Poverty Level: ' + fpl;
document.getElementById("demo").innerHTML = result6;
}
здесь у вас есть код без ошибок и исправлений.
function FPL() {
//parse the value to get the number.
var income = parseFloat('4200.00');
var fs = '1';
var fpl;
if (fs == '1') {
if (income < parseFloat('1022.00'))
fpl = "0-100%";
else if (income > parseFloat('1022.00') && income < parseFloat('1882.00'))
fpl = "101-185%";
else if (income > parseFloat('1882.00') && income < parseFloat('2033.00'))
fpl = "186%-200%";
else if (income < parseFloat('2033.00'))
fpl = "'201% & Over";
else
fpl = 'default value';
}
result6 = 'Federal Poverty Level: ' + fpl;
document.getElementById("demo").innerHTML = result6;
}
FPL();
<p id="demo"></p>