+ 2
I made a few little changes to the second answer to make it show 2 alerts without using if-statements: let age = prompt("input your age"); let year = 2019 - age; let answers = !age ? ["Please enter a number"] : year > 120 ? ["InA", "YoP"] : ["You were born in " + year]; answers.forEach(alert); The changes include: - Replaced expression evaluating to a single string to one evaluating to an Array of string - renamed answer to answers to correspond with it potentially being multiple strings. - Replaced single alert with answers.forEach(alert) so alert would be called on each and every string. - I removed the `${ characters because the template literal doesn't seem helpful there.
6th Jul 2019, 10:58 PM
Josh Greig
Josh Greig - avatar