-
Notifications
You must be signed in to change notification settings - Fork 0
/
objects.js
111 lines (92 loc) · 2.96 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
// writing methods open() and close()
var umbrella = {
color: "pink",
isOpen: true,
open: function() {
if (umbrella.isOpen === true) {
return "The umbrella is already opened!";
} else {
umbrella.isOpen = true;
return "Julia opens the umbrella!";
}
},
// your code goes here
close: function(){
if (umbrella.isOpen === false){
return "The umbrella is already closed!";
} else {
umbrella.isOpen = false;
return "Julia closes the umbrella!";
}
}
};
console.log(umbrella.close());
///////////////\\\\\\\\\\\\\\\\\\\////////////////////
// a breakfast object
var breakfast = {
name: "The Lumberjack",
price: 9.95,
ingredients: ["eggs", "sausage", "toast", "hashbrowns", "pancakes"]
};
///////////////\\\\\\\\\\\\\\\\\\\////////////////////
// add a printAccountSummary() method that returns a message with the balance and interest rate:
var savingsAccount = {
balance: 1000,
interestRatePercent: 1,
deposit: function addMoney(amount) {
if (amount > 0) {
savingsAccount.balance += amount;
}
},
withdraw: function removeMoney(amount) {
var verifyBalance = savingsAccount.balance - amount;
if (amount > 0 && verifyBalance >= 0) {
savingsAccount.balance -= amount;
}
},
printAccountSummary: function accountSummary(){
return `Welcome!
Your balance is currently $${this.balance} and your interest rate is ${this.interestRatePercent}%.`;
}
};
console.log(savingsAccount.printAccountSummary());
///////////////\\\\\\\\\\\\\\\\\\\////////////////////
/*
Create an object called facebookProfile. The object should have 3 properties:
your name
the number of friends you have, and
an array of messages you've posted (as strings)
The object should also have 4 methods:
postMessage(message) - adds a new message string to the array
deleteMessage(index) - removes the message corresponding to the index provided
addFriend() - increases the friend count by 1
removeFriend() - decreases the friend count by 1
*/
var facebookProfile = {
name: "Syk Houdeib",
friends: 400,
posts: ["2017 almost done", "loading 2018, 12 hours remaining"],
postMessage: function addMessage(message){
facebookProfile.posts.unshift(message);
},
deleteMessage: function removeMessage(index){
facebookProfile.posts.splice(index, 1);
},
addFriend: function(){
facebookProfile.friends += 1;
},
removeFriend: function(){
facebookProfile.friends -= 1;
}
};
///////////////\\\\\\\\\\\\\\\\\\\////////////////////
var donuts = [
{ type: "Jelly", cost: 1.22 },
{ type: "Chocolate", cost: 2.45 },
{ type: "Cider", cost: 1.59 },
{ type: "Boston Cream", cost: 5.99 }
];
donuts.forEach(function(donut){
var summary = `${donut.type} donuts cost $${donut.cost} each`;
console.log(summary);
});