-
Notifications
You must be signed in to change notification settings - Fork 0
/
objects.html
75 lines (52 loc) · 1.66 KB
/
objects.html
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>objects tested</title>
</head>
<body>
<script type="text/javascript">
var object = {
property: "result",
name: "nick",
age: 28,
sex: "yes, please",
"My Height": "really light. I need to eat more.",
oneWord: "one word",
// This is a METHOD because it is a function within an object
// methods need to be declared with "name: function() {}"
resetAll: function() {
console.log(object.age);
}
};
// outside an object, declare a function with "function name() {}"
function nameMe() {
console.log(object.property);
console.log("__________________");
}
// click event to activate functions
document.onkeyup = function() {
// Captures the key press, converts it to lowercase, and saves it to a variable.
var letter = String.fromCharCode(event.keyCode).toLowerCase();
if (letter === "m") {
//declare the nameMe function, located within this same object
nameMe();
}
if (letter === "r") {
//use . synax to call resetAll() function because it is in the "object" object
object.resetAll();
}
}
// // console.logging object
// console.log("__________________");
// console.log(object);
// //able to console.log multiple things in one line
// console.log(object.name, object.sex, object.age);
// // need to use object.property syntax
// console.log(object.property);
// console.log(object.oneWord);
// // need to use [] and "" to declare strings
// console.log(object["My Height"]);
</script>
</body>
</html>