forked from bloominstituteoftechnology/Basic-JavaScript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproject-3.js
More file actions
108 lines (94 loc) · 1.92 KB
/
project-3.js
File metadata and controls
108 lines (94 loc) · 1.92 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
99
100
101
102
103
104
105
106
107
108
const makeCat = (name, age) => {
const newCat = {
name,
age,
meow() {
return 'Meow!';
}
};
return newCat;
};
const addProperty = (object, property) => {
object[property] = null;
return object;
};
const invokeMethod = (object, method) => {
object[method]();
};
const multiplyMysteryNumberByFive = (mysteryNumberObject) => {
return mysteryNumberObject.mysteryNumber * 5;
};
const deleteProperty = (object, property) => {
delete object[property];
return object;
};
const newUser = (name, email, password) => {
const object = {
name,
email,
password
};
return object;
};
const hasEmail = (user) => {
if (user.email) {
return true;
}
return false;
};
const hasProperty = (object, property) => {
if (object[property]) {
return true;
}
return false;
};
const verifyPassword = (user, password) => {
if (user.password === password) {
return true;
}
return false;
};
const updatePassword = (user, newPassword) => {
user.password = newPassword;
return user;
};
const addFriend = (user, newFriend) => {
user.friends.push(newFriend);
return user;
};
const setUsersToPremium = (users) => {
for (let i = 0; i < users.length; i++) {
users[i].isPremium = true;
}
return users;
};
const sumUserPostLikes = (user) => {
let sumOfLikes = 0;
for (let i = 0; i < user.posts.length; i++) {
sumOfLikes += user.posts[i].likes;
}
return sumOfLikes;
};
const addCalculateDiscountPriceMethod = (storeItem) => {
storeItem.calculateDiscountPrice = () => {
const discount = storeItem.price * storeItem.discountPercentage;
return storeItem.price - discount;
};
return storeItem;
};
module.exports = {
makeCat,
addProperty,
invokeMethod,
multiplyMysteryNumberByFive,
deleteProperty,
newUser,
hasEmail,
hasProperty,
verifyPassword,
updatePassword,
addFriend,
setUsersToPremium,
sumUserPostLikes,
addCalculateDiscountPriceMethod
};