4.1 Interacting with the User
4.1.1 The alert() Method
The message for the alert dialog box is a string of text (or a valid expression) enclosed in double quotes, and sent as a single argument to the alert() method. HTML tags are not rendered within the message string but you can use the escape sequences, \n and \t .
alert("String of plain text"); alert(expression);
alert("Phone number is incorrect"); alert(a + b);
4.1.2 The Prompt Box
prompt(message); prompt(message, defaultText);
prompt("What is your name? ", ""); prompt("Where is your name? ", name);
Figure 4.4. Prompt with a default argument.
Figure 4.5. Prompt without a default.
Figure 4.6. User types in the prompt box.
4.1.3 The Confirm Box
The confirm dialog box is used to confirm a user's answer to a question. A question mark will appear in the box with an OK button and a Cancel button. If the user presses the OK button, true is returned; if he presses the Cancel button, false is returned. This method takes only one argument, the question you will ask the user.