How to use prompt repeatedly till we get a valid input


#1

//here in this code if I give wrong input again after the prompt, it just continues

var answer = prompt("Add your question here!");

switch(answer) {
case "what's an apple":
console.log("its a fruit ...u idiot");
break;

case "what's an aeroplane":
console.log("bro are you high?");
break;

// Add your code here!
default:
console.log("we don't answer that");
prompt("ask again");
}


#2

have loops already been covered? You can use do while loop


#3

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.