-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathObjects.js
More file actions
98 lines (77 loc) · 2.31 KB
/
Objects.js
File metadata and controls
98 lines (77 loc) · 2.31 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
var document = {
write() {},
};
// TODO LESSON 1
// person is object, name until height is properties
var person = {
name: "John",
age: 31,
favColor: "green",
height: 183,
};
// call and output the objects
console.log(person);
let object1 = person.name; // output 'John'
let object2 = person.height; // output 183
let object3 = person["age"]; // output 31
let object4 = person["name"]; // output 'John'
let object5 = person["favColor"]; // output 'green'
console.log(object1, object2, object3, object4, object5);
// count how many number of character in a property or string
console.log(person.favColor.length); // output 5
document.write(`There is ${person.favColor.length} character `); // output 5 character di browser
// calculate cubed volume
function volumeCubed(p, l, t) {
return p * l * t;
}
var cubed = {
p: 250,
l: 100,
t: 500,
};
console.log(volumeCubed(cubed.p, cubed.l, cubed.t));
document.write(`Volume ${volumeCubed(cubed.p, cubed.l, cubed.t)} `);
// TODO LESSON 2
var person = {
name: "John",
age: 31,
favColor: "green",
height: 183,
};
// call old person
console.log(person);
console.log(person.name);
console.log(person.age);
console.log(person.favColor);
console.log(person.height);
// change value properties in the object of person
function newPerson(name, age, color, height) {
person.name = name;
person.age = age;
person.favColor = color;
person.height = height;
}
// create a construction function
newPerson("Willy", 18, "white", 200);
// call new person
console.log(person);
console.log(person.name);
console.log(person.age);
console.log(person.favColor);
console.log(person.height);
// test case
var flightIs = {
numberIs: "",
statusIs: "",
};
function flightAnnouncement(flightNumber, flightStatus) {
flightIs.numberIs = flightNumber;
flightIs.statusIs = flightStatus;
}
flightAnnouncement("NGT 929", "landed!");
console.log(`The Flight ${flightIs.numberIs} has ${flightIs.statusIs} `);
document.write(`The Flight ${flightIs.numberIs} has ${flightIs.statusIs} `);
flightAnnouncement("Boeing 707", "delayed!");
console.log(`The Flight ${flightIs.numberIs} has ${flightIs.statusIs} `);
document.write(`The Flight ${flightIs.numberIs} has ${flightIs.statusIs} `);
// TODO LESSON 3