I have a really simple Javascript function that's based off of a variable taken from a prompt. If the input in the prompt is neither a number nor a string, I want it to automatically loop back to the prompt so the user can write the input again. Is this code correct for that?
var a = prompt("please enter a number");
function tys() {
if (typeof a == 'string') {
document.write("You exited.");
} else if (isNaN(a)) {
document.write(a-10);
} else {
document.write("Input invalid. Please write another input.");
tys();
}
}
Aucun commentaire:
Enregistrer un commentaire