JS Fundamentals - Interaction: alert, prompt, confirm Flashcards

1
Q

alert

A

The mini-window with the message is called a modal window. The word “modal” means that the visitor can’t interact with the rest of the page, press other buttons, etc, until they have dealt with the window. In this case – until they press “OK”.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

prompt

A

result = prompt(title, [default]);
It shows a modal window with a text message, an input field for the visitor, and the buttons OK/Cancel.

title
The text to show the visitor.
default
An optional second parameter, the initial value for the input field.

The visitor can type something in the prompt input field and press OK. Then we get that text in the result. Or they can cancel the input by pressing Cancel or hitting the Esc key, then we get null as the result.

The call to prompt returns the text from the input field or null if the input was canceled.

In IE: always supply a default
The second parameter is optional, but if we don’t supply it, Internet Explorer will insert the text “undefined” into the prompt.

Run this code in Internet Explorer to see:

let test = prompt("Test");
So, for prompts to look good in IE, we recommend always providing the second argument:

let test = prompt(“Test”, ‘’); //

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

confirm

A

The function confirm shows a modal window with a question and two buttons: OK and Cancel.

The result is true if OK is pressed and false otherwise

let isBoss = confirm(“Are you the boss?”);

alert( isBoss ); // true if OK is pressed.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly