//sample solution
var myAge = prompt("How old are you?")
/* a simple if else statement
if (myAge >= 18) {
answer = "adult";
}
else {
answer = "non-adult" ;
}*/
// rewrite the code above using a ternary operator
answer = myAge >= 18 ? "adult" : "non-adult";
No comments:
Post a Comment