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?
Advertisement
Answer
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);
}