Skip to content

Commit 94b7128

Browse files
committed
Add alert and prompt function explanation
1 parent a36e485 commit 94b7128

File tree

1 file changed

+67
-0
lines changed

1 file changed

+67
-0
lines changed

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

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,70 @@ Now try invoking the function `prompt` with a string input of `"What is your nam
1616

1717
What effect does calling the `prompt` function have?
1818
What is the return value of `prompt`?
19+
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:
33+
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.
40+
41+
Return value:
42+
43+
alert() does not return any value — its return value is undefined.
44+
45+
2. The prompt() function
46+
47+
Code:
48+
49+
let myName = prompt("What is your name?");
50+
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”)
80+
81+
myName === null (if Cancelled)
82+
83+
Purpose:
84+
prompt() is used to get text input from the user through a browser dialog.
85+

0 commit comments

Comments
 (0)