I need help with modifying a calculator created by a former colleague at my workplace. Unfortunately, I haven't been able to contact them and I was hoping someone here could assist me. My knowledge of javascript is limited, so please bear with me if my question sounds silly or if I'm overlooking something obvious. I've searched everywhere for information but couldn't find anything, so any guidance would be greatly appreciated!
Here is the current code snippet that I want to update:
function date(){
var the_date = new Date();
enter code herethe_year = the_date.getFullYear();
ret_age=Number(document.calculator.year.value);
gender=Number(document.calculator.sex.value);
a=the_year-ret_age;
if (a<=36)
{
document.calculator.number3.value=68;
}
else if (a>36 && a<=45)
{
document.calculator.number3.value=67;
}
else if (a>=45 && a<=60)
{
document.calculator.number3.value=66;
}
else if (a>60 && gender==1)
{
document.calculator.number3.value=65;
}
else if (a>60 && gender==0)
{
document.calculator.number3.value=65;
}
else
{
alert("Our calculator is having trouble working out your state pension age. You have been given a default age of 68. Feel free to change it.");
document.calculator.number3.value=68;
}
}
I am looking to add these new 'else if' options, but I suspect there might be an issue with the number of conditions in each one.
else if (a>60 && gender==0)
{
document.calculator.number3.value=65;
}
else if (a>60 && a<=62 && gender==0)
{
document.calculator.number3.value=62;
}
else if (a>63 && gender==0)
{
document.calculator.number3.value=60;
}
Am I making a mistake by trying to use e.g., a<61 && <=63
in conjunction with the gender condition? It seems to only work when I specify one condition for the number, like a<60
.
Is there a way to incorporate these two conditions in the else if statement, or should I approach this differently?
Your assistance would be greatly appreciated - once again, I apologize if my explanation is unclear. If you need more information to assist me, please let me know! I'm feeling a bit lost. Thank you! :)