You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: Sprint-1/4-stretch-explore/chrome.md
+11-55Lines changed: 11 additions & 55 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -17,69 +17,25 @@ Now try invoking the function `prompt` with a string input of `"What is your nam
17
17
What effect does calling the `prompt` function have?
18
18
What is the return value of `prompt`?
19
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:
20
+
Answers:
33
21
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
40
23
41
-
Return value:
24
+
console.alert("Hello world!");
42
25
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.
44
29
45
30
2. The prompt() function
46
31
47
-
Code:
48
-
49
32
let myName = prompt("What is your name?");
50
33
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".
80
35
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".
82
39
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.
0 commit comments