@@ -5,68 +5,99 @@ const makeCat = (name, age) => {
5
5
// add an age property to the object with the value set to the age argument
6
6
// add a method called meow that returns the string 'Meow!'
7
7
// return the object
8
+ const cat = {
9
+ age,
10
+ name,
11
+ meow ( ) {
12
+ return 'Meow!' ;
13
+ }
14
+ } ;
15
+ return cat ;
8
16
} ;
9
17
10
18
const addProperty = ( object , property ) => {
11
19
// add the property to the object with a value of null
12
20
// return the object
13
21
// note: the property name is NOT 'property'. The name is the value of the argument called property (a string)
22
+ object [ property ] = null ;
23
+ return object ;
14
24
} ;
15
25
16
26
const invokeMethod = ( object , method ) => {
17
27
// method is a string that contains the name of a method on the object
18
28
// invoke this method
19
29
// nothing needs to be returned
30
+ object [ method ] ( ) ;
20
31
} ;
21
32
22
33
const multiplyMysteryNumberByFive = ( mysteryNumberObject ) => {
23
34
// mysteryNumberObject has a property called mysteryNumber
24
35
// multiply the mysteryNumber property by 5 and return the product
36
+ const product = mysteryNumberObject . mysteryNumber * 5 ;
37
+ return product ;
25
38
} ;
26
39
27
40
const deleteProperty = ( object , property ) => {
28
41
// remove the property from the object
29
42
// return the object
43
+ delete object [ property ] ;
44
+ return object ;
30
45
} ;
31
46
32
47
const newUser = ( name , email , password ) => {
33
48
// create a new object with properties matching the arguments passed in.
34
49
// return the new object
50
+ const obj = { name, email, password } ;
51
+ return obj ;
35
52
} ;
36
53
37
54
const hasEmail = ( user ) => {
38
55
// return true if the user has a value for the property 'email'
39
56
// otherwise return false
57
+ if ( user . email ) { return true ; }
58
+ return false ;
40
59
} ;
41
60
42
61
const hasProperty = ( object , property ) => {
43
62
// return true if the object has the value of the property argument
44
63
// property is a string
45
64
// otherwise return false
65
+ if ( Object . prototype . hasOwnProperty . call ( object , property ) ) { return true ; }
66
+ return false ;
46
67
} ;
47
68
48
69
const verifyPassword = ( user , password ) => {
49
70
// check to see if the provided password matches the password property on the user object
50
71
// return true if they match
51
72
// otherwise return false
73
+ if ( password === user . password ) { return true ; }
74
+ return false ;
52
75
} ;
53
76
54
77
const updatePassword = ( user , newPassword ) => {
55
78
// replace the existing password on the user object with the value of newPassword
56
79
// return the object
80
+ user . password = newPassword ;
81
+ return user ;
57
82
} ;
58
83
59
84
const addFriend = ( user , newFriend ) => {
60
85
// user has a property called friends that is an array
61
86
// add newFriend to the end of the friends array
62
87
// return the user object
88
+ user . friends . push ( newFriend ) ;
89
+ return user ;
63
90
} ;
64
91
65
92
const setUsersToPremium = ( users ) => {
66
93
// users is an array of user objects.
67
94
// each user object has the property 'isPremium'
68
95
// set each user's isPremium property to true
69
96
// return the users array
97
+ users . forEach ( ( item ) => {
98
+ item . isPremium = true ;
99
+ } ) ;
100
+ return users ;
70
101
} ;
71
102
72
103
const sumUserPostLikes = ( user ) => {
0 commit comments