-
Notifications
You must be signed in to change notification settings - Fork 97
Expand file tree
/
Copy pathindex.js
More file actions
60 lines (43 loc) · 1.87 KB
/
index.js
File metadata and controls
60 lines (43 loc) · 1.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
// 1 - The .onload is a Global event that happens every time the browser window loads.
// here we are using it to fire a function that will log out a message in the console.
window.onload = () => {
console.log("Hey student, welcome to your console!")
// We'll add an event listener to the submit button so we can prevent the window from reloading when we click it.
const submitButton = document.getElementById("submit-button").addEventListener("click", event => {
event.preventDefault(),
// this next line calls the sayHi function & passes it the value of the name input on the form from the target value of the event that's called when the form is submitted.
sayHi(event.target.form.name.value)
})
}
// 2 - This function is called when a user clicks on the button in the HTML.
// Can you make the text "hello" log to the console?
const sayHello = () => {
return "Hello!"
}
// 3 - In the Chrome Console type out the name of each of these variables
// ... one at a time and see what is returned.
const arr1 = [2, 4, 6, 77, 90, 12, 1]
const num1 = 8039
const name1 = "Chrome Console"
const object1 = {
name: "Laura",
phone: "214-888-0000",
email: "lauracan@email.com",
username: "fantastic-laura",
id: 69002,
}
// 3.5 - Can you add statements below to log to the console each of the variables above?
// This variable will hold text values for us
let inputFieldValue = ""
// 4 - This function will change the value assigned to inputFieldValue
// go back to the web page, open the console, and type into the Name field to see what is happening.
const setInputFieldValue = (val) => {
inputFieldValue = val
console.log(val)
console.log("inputFieldValue: " + inputFieldValue)
}
// 5 - This function uses the field input to say hello to a name given by the user.
const sayHi = (data) => {
greetingString = "Hi, " + data + "!"
return console.log(greetingString)
}