jeudi 7 mai 2020

Why isn't null working properly in a while-loop?

var age = "";
while( (age == "") || (age != null) && || isNaN(age)) {
    age = prompt("How old are you?");
}
if (age <= 14){
    alert("You're too young!");
} else if (age >= 15) {
    alert("Welcome on board!");
}

I'm not allowed to use functions for this exercice and I can't figure out why the prompt gives me You're too young when I click cancel. I know that I should use functions in order to solve this but I've been asked not to.

            var age = "";
while( (age == "") || (age != null) && || isNaN(age)) {
    age = prompt("How old are you?");
}
if (age <= 14){
    alert("You're too young!");
} else if (age >= 15) {
    alert("Welcome on board!");
}

Aucun commentaire:

Enregistrer un commentaire