More about conditionals

Conditionals break down into three parts: the if section, where we do our test; the then section, where we put the part of the script we want to do if the result is true; and an optional else section, which contains the part of the script we want to have happen if the result of the test is not true. The contents of what we’re testing in the if section are in parentheses, and the contents of the other two sections are each contained in braces.

To confirm a choice:

1.
if (confirm("Are you sure you want to do that?")) {
The confirm() method takes one parameter (the question we want to ask the user) and returns either true or false, depending on the user’s response.
2.
alert("You said yes");
As shown in Figure 2.4, if the ...

Get JavaScript and Ajax for the Web: Visual QuickStart Guide, Seventh Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.