Reputation: 9
If I were to have a prompt in my code like this:
prompt("What is your favorite animal?");
Is there a way to store the answer?
Upvotes: -1
Views: 3392
Reputation: 152
Just assign the function call to a variable and don't forget to perform answer checks
var answer = prompt("What is your favorite animal?");
if (answer != null && answer.length !== 0) {
// do your stuff here
alert(answer);
}
Upvotes: 3