Why doesn't this conditional work?

Hey I’m getting the same issue, here’s my code:

const lifePhase = (age) => {
if(age >= 0 && age <= 3){
return ‘baby’;;
}else if (age >= 4 && age <= 12){
return ‘child’;
}else if (age >= 13 && age <= 19){
return ‘teen’;
}else if (age >= 20 && age <= 64){
return ‘adult’;
}else if (age >= 65 && age <= 140){
return ‘senior citizen’;
}else if( age < 0 || age > 140){
return ‘This is not a valid age.’;
}
}

Don’t know if it’s the cause since i’m also still learning but you have 2 times ; after the return ‘baby’

what Tim said and you last line (I think) needs to just be “else”… this works:

const lifePhase = (age) =>{
if (age >= 0 && age <= 3) {
return ‘baby’;
}
else if (age >= 4 && age <= 12) {
return ‘child’;
}
else if (age >= 13 && age <= 19) {
return ‘teen’;
}
else if (age >= 20 && age <= 64) {
return ‘adult’;
}
else if (age >= 65 && age <= 140) {
return ‘senior citizen’;
}
else {
return ‘This is not a valid age’;
}
}

1 Like