Working with confirm and prompt
As mentioned earlier confirm is used for choosing an option from two choices. It will return a Boolean value. Let’s have a look at the example.
var v=window.confirm("Are you sure you are ok?");
Have you observed the fact? Right!
If you are clicked on OK it returns true so value of v is true. If you are clicked on Cancel it returns false so value of v is false, that is displayed dynamically on an alert box based on the click.
And assignment as follows:
v = 10;
We can even combine declaration and assignment in a single statement. That can be
var v = 10;
var v=window.prompt("Enter the Number","10");
Out put here is self explanatory. We get a prompt dialog box that takes input in prompt box.
The given input is captured or stored in variable v. Value of v is displayed in an alert message.
Here Enter the Number in prompt box title and 10 is the default value.
Next Chapter: prompt, confirm ,alert all together
Previous Chapter: More practical Approach
More Tutorials: Tutorial Index