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
+34Lines changed: 34 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -16,3 +16,37 @@ Now try invoking the function `prompt` with a string input of `"What is your nam
16
16
17
17
What effect does calling the `prompt` function have?
18
18
What is the return value of `prompt`?
19
+
20
+
Response:
21
+
22
+
1. Call the alert function
23
+
In the console, typing 'alert("Hello world!");'
24
+
25
+
Effect:
26
+
A small pop-up dialog box appears in the browser window with the message "Hello world!" and an OK button. The dialog is modal, so it blocks interaction with the web page until you click OK.
27
+
28
+
2. Call the prompt function typing:
29
+
30
+
let myName = prompt("What is your name?");
31
+
32
+
Effect:
33
+
Another pop-up appears, this time with the message "What is your name?", a text input field, and OK/Cancel buttons.
34
+
35
+
When typed something and press OK, the string typed is returned and stored in the variable myName.
36
+
If pressed Cancel or close the dialog without entering anything, the return value is null.
37
+
38
+
3. Check the return value
39
+
After entering a name (e.g., "Carlos") and clicking OK, you can check:
40
+
41
+
console.log(myName);
42
+
Output in the console:
43
+
44
+
Carlos
45
+
46
+
In summary:
47
+
alert() displays a message and returns nothing (undefined).
48
+
prompt() displays a message with an input field and returns either of one value:
49
+
50
+
The input string (if OK is clicked)
51
+
null (if Cancel is clicked or the dialog is closed without input)
This shows that console is an object containing many methods.
20
+
11
21
Try also entering `typeof console`
12
22
23
+
Typing typeof console returns:
24
+
25
+
"object"
26
+
This confirms that console is an object data type.
27
+
28
+
console stores a collection of methods and properties used for debugging and logging information in the browser. It's a built-in object that provides access to the browser's debugging console. It contains methods like:
29
+
30
+
log() - for general output
31
+
32
+
error() - for error messages
33
+
34
+
warn() - for warnings
35
+
36
+
info() - for informational messages
37
+
38
+
assert() - for conditional logging
39
+
40
+
table() - for displaying tabular data
41
+
42
+
clear() - for clearing the console
43
+
44
+
And many more
45
+
13
46
Answer the following questions:
14
47
15
48
What does `console` store?
16
49
What does the syntax `console.log` or `console.assert` mean? In particular, what does the `.` mean?
50
+
51
+
The dot (.) is the member access operator (also called the property accessor) in JavaScript.
52
+
53
+
When it shows console.log:
54
+
55
+
console is the object
56
+
57
+
. means "access a property of this object"
58
+
59
+
log is a property of the console object (specifically a method, which is a function stored as a property)
60
+
61
+
So console.log means "access the log property of the console object." Since log is a function, we can then call it with parentheses: console.log("Hello").
62
+
This dot notation is how JavaScript allows objects to contain related data and functionality, organizing code into logical groups.
0 commit comments