Prompt, Alert, Confirm
// Input must be stored in a variable or else it goes nowhere!
let userResponse = prompt("What is your name?");
If the user clicks cancel, then the
consoleis a great way to give output as a developer (testing, errors, warnings) but general users do not see the console window! If you want to give a quick pop-up of information to the user (without any input from the user), you can use the
General Alert window with OK button
alert()function is very simple. It takes a string and returns nothing. To use it, you just call it with whatever you want shown in the pop-up box.
alert("The sky is falling, the sky is falling!");
Maybe you don't want text from the user but rather a YES or NO (or perhaps
confirm()function to ask the user a question and present them with two choices that equate to
Press OK for yes, CANCEL for no
The ability to retrieve a boolean value from the user can be very useful. The
confirm()function takes a string as input and returns a boolean.
let userAnswer = confirm("You will become a zombie");
While many examples could be provided of the three methods listed, it is much more rewarding if you try them out yourself.