I have to calculate the premium from a rate chart based on a person's age and the amount of insurance they request. I started out using if
/switch
statements, but the code is getting too long and seems pretty redundant.
var premium;
var beneAmt = $('#PrimaryApplicantTTLBenefitAmountInput').val();
var age = $('#PrimaryApplicantAge').val();
if (50000 <= beneAmt < 75000) {
switch (true) {
case (age < 30):
premium = 2.00;
break;
case (30 <= age < 40):
premium = 2.50;
break;
case (40 <= age < 50):
premium = 5.00;
break;
case (50 <= age < 60):
premium = 15.00;
break;
case (60 <= age < 65):
premium = 21.50;
break;
case (65 <= age < 70):
premium = 20.80;
break;
case (70 <= age < 75):
premium = 23.25;
break;
case (age >= 75):
premium = 35.00;
break;
}
} else if (75000 <= beneAmt < 100000) {
switch (true) {
case (age < 30):
premium = 3.00;
break;
case (30 <= age < 40):
premium = 3.75;
break;
case (40 <= age < 50):
premium = 7.50;
break;
case (50 <= age < 60):
premium = 22.50;
break;
case (60 <= age < 65):
premium = 32.25;
break;
case (65 <= age < 70):
premium = 31.20;
break;
case (70 <= age < 75):
premium = 34.88;
break;
case (age >= 75):
premium = 52.50;
break;
}
} else if (100000 <= beneAmt < 125000) {
switch (true) {
case (age < 30):
premium = 4.00;
break;
case (30 <= age < 40):
premium = 5.00;
break;
case (40 <= age < 50):
premium = 10.00;
break;
case (50 <= age < 60):
premium = 30.00;
break;
case (60 <= age < 65):
premium = 43.00;
break;
case (65 <= age < 70):
premium = 41.60;
break;
case (70 <= age < 75):
premium = 46.50;
break;
case (age >= 75):
premium = 70.00;
break;
}
}
How else could I go about this?