Skip to content

Commit 2128a93

Browse files
committed
Explaining alert() and prompt() functions
1 parent 3adb077 commit 2128a93

File tree

1 file changed

+11
-55
lines changed

1 file changed

+11
-55
lines changed

Sprint-1/4-stretch-explore/chrome.md

Lines changed: 11 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -17,69 +17,25 @@ Now try invoking the function `prompt` with a string input of `"What is your nam
1717
What effect does calling the `prompt` function have?
1818
What is the return value of `prompt`?
1919

20-
1. The alert() function
21-
22-
Code:
23-
24-
alert("Hello world!");
25-
26-
Effect:
27-
28-
When you call alert("Hello world!") in the Chrome Console:
29-
30-
A modal dialog box (popup window) appears on the screen.
31-
32-
It displays the message:
20+
Answers:
3321

34-
Hello world!
35-
36-
The dialog has an “OK” button that you must click before continuing.
37-
38-
Purpose:
39-
It’s used to display information to the user — a simple way to show messages or debugging output in the browser.
22+
1. The alert() function
4023

41-
Return value:
24+
console.alert("Hello world!");
4225

43-
alert() does not return any value — its return value is undefined.
26+
When calling the function alert("Hello world!") in the Chrome Console.
27+
A window popup the the message displaying "Hello world!" on the screen.
28+
That windows has an “OK” button that needs to click before continuing.
4429

4530
2. The prompt() function
4631

47-
Code:
48-
4932
let myName = prompt("What is your name?");
5033

51-
Effect:
52-
53-
When you call this:
54-
55-
A popup dialog appears with:
56-
57-
A message: "What is your name?"
58-
59-
A text input box
60-
61-
“OK” and “Cancel” buttons.
62-
63-
The user can type something (e.g., Alice) and click “OK” or “Cancel”.
64-
65-
Return value:
66-
67-
If the user types something (e.g., "Alice") and clicks OK
68-
prompt() returns the string "Alice".
69-
70-
If the user clicks Cancel
71-
prompt() returns null.
72-
73-
So after running:
74-
75-
let myName = prompt("What is your name?");
76-
77-
You’ll have:
78-
79-
myName === "Alice" (if entered “Alice”)
34+
When calling that function the window display a message "What is your name?" and after the user input a response the value is stored in the variable "myName".
8035

81-
myName === null (if Cancelled)
36+
That window dialog has two buttons: “OK” and “Cancel”.
37+
The user can type something like "Carlos" and click “OK” or “Cancel”.
38+
If the user types something like "Carlos" and clicks OK the prompt function returns the string "Carlos".
8239

83-
Purpose:
84-
prompt() is used to get text input from the user through a browser dialog.
40+
The purpose of prompt() is to get text input from the user through a window dialog.
8541

0 commit comments

Comments
 (0)