What am I doing wrong here && how would you improve this?

const lifePhase = (age) => { switch (age) { case age <= 3: return 'baby'; case age > 4 && age < 12: return 'child'; case age > 13 && age < 19: return 'teen'; case age > 20 && age < 64: return 'adult'; case age > 65 && age < 140: return 'senior citizen'; case age < 0 || age > 140: return 'This is not a valid age'; } }; console.log(lifePhase(5));

Does the code not pass the lesson checker?

It does not maybe because I used switch instead of if/else if/else.

Does the exercise ask for if…else if…else?

Consider whether any values will slip through your logic, especially floats.

consider case age > 4 && age < 12: you are not accounting for the age being exactly 4 or 12

I appreciate your replies gentlemen. :mechanical_arm:

1 Like