-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathObjects.js
121 lines (93 loc) · 2.58 KB
/
Objects.js
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
// an object is a value type consisting of key value pairs.
// Javascript has two main value types primitives and objects.
// What is a primitive? Strings, Numbers, Booleans, Null, Undefined.
// and in ES6 Symbols
// Variables become known as properties
// if a variable is part of an object it is called a property
var car = {
wheels: 4,
color: 'white',
mpg: 34,
engine: 5,
gallons: 17
};
// DOT NOTATION
var car = {};
// object.property = value;
car.wheels = 4;
car.color = 'white';
car.mpg = '34';
car.engine = 5;
car.gallons = 17;
// BRACKET NOTATION
var car = {};
// object['property'] = value;
//Challenge
// build a person with object literal notation
// use three property values consiting of a string, numnber and boolean
var humanBeing = {
hungry: true,
age: 25,
height: '5\10'
// As you can see I turned what might look
//like a number into a string and use the escape clause to keep
//the single quote in the string text.
};
// BUILD Snowman
var snowman = {
isSnow: yes,
color: 'orange',
madeOfSnowballs: 8,
'first name': 'Frosty'
};
// challenge
// build a house object
// add 4 property values with dot notation with at least one value type if string, number and boolean
// add 3 property values with bracket notation with 3 property names that can only be added with bracket
// notation rather than dot notation
house = {};
house.doors = 4;
house.bedrooms = 7;
house.address = '4219 S. Othello St';
house.office = true;
house.pool = true;
house.gym = true;
house.saferoom = true;
house.sauna = true;
house.greenhouse = true;
// Object constructor functions
// Object constructor functions allow us to create many objects
// using a function
// practice
var home = {
rooms: 4,
apartment: false,
color: 'brown',
swimmingPool: true,
state: 'WA',
city: 'Seattle'
};
function Home(rooms, apartment, color, swimmingPool, state, city) {
this.rooms = rooms;
this.apartment = apartment;
this.color = color;
this.swimmingPool = swimmingPool;
this.state = state;
this.city = city;
};
// create book with object literal notation
// create libaray with object constructor function
// create 5 instances of book
var book = {
author: 'Victor Hugo',
title: 'Les Miserables',
pages: 1200
};
function Book(author, title, pages) {
this.author = author;
this.title = title;
this.pages = pages;
};
var book1 = new Book('Charles Dickenson', 'Tale of Two Cities', 567);
var book2 = new Book('Definitive JavaScript', 'David Flanigan', 857);
var book3 = new Book('Frankenstien', 'Mary Shelly', 454);