other functions(above)
function calculateAge(){
const errorDay="Days must be 1 ... 31.";
const errorMonth="Months must be 1 ... 12.";
const errorYear= "Year is too big";
let century = 0;
let bornYear= 0;
let age =0;
bornYear=[century + idcode.substring(4,6)];
age = (current_year-bornYear);
document.getElementById("age").innerHTML=age;
if ((idcode.substring(0,2) > 31) || (idcode.substring(0,2) < 1)){
document.getElementById("error").innerHTML= errorDay;
}
else if((idcode.substring(2,4) > 12) || (idcode.substring(2,4) < 1)){
document.getElementById("error").innerHTML= errorMonth;
}
else if(bornYear > current_year){
document.getElementById("error").innerHTML= errorYear;
}
} --end of function
I want to use return statement here so that the program stops and only shows error when there is an error. It doesn't stop now, the rest of the functions continue to work while displaying the error. How do I write return statement within these if else statements? (beginner here)
Aucun commentaire:
Enregistrer un commentaire