-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
99 lines (89 loc) · 2.68 KB
/
app.js
File metadata and controls
99 lines (89 loc) · 2.68 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
console.log('App is connected');
// Protagonist of our application
const barbie = {
name: 'Barbie',
wardrobe: [],
wallet: 0,
// Element that will hold the game screen
element: document.querySelector('#barbie'),
// Game Screen
render: () => {
barbie.element.innerHTML = `
<h1>${barbie.name} Status</h1>
<h3>${barbie.name} works as a ${barbie.career.name} </h3>
<h3> Each week ${barbie.name} takes home $${barbie.career.income}</h3>
<h3> Currently ${barbie.name} has $${
barbie.wallet
} in their bank account</h3>
<div> <h2>Wardrobe Contains: </h2>
<ul>${barbie.wardrobe
.map((item) => {
return `<li>
${barbie.name} has a ${item.color}
${item.name} made by ${item.designer}
that is worth ${item.price} in size
${item.size}
</li>`;
})
.join('')}</ul>
</div>
`;
},
};
class Career {
constructor(name, description, income, id) {
this.name = name;
this.description = description;
this.income = income;
}
}
// Instantiate a new career and assigning it to barbie's career property
const barbieCareer = new Career(
'Doctor',
'helps people with their boo boos',
2938
);
barbie.career = barbieCareer;
class Clothing {
constructor(name, designer, color, type, size, price) {
this.name = name;
this.designer = designer;
this.color = color;
this.type = type;
this.size = size;
this.price = price;
}
}
const birkin = new Clothing(
'Birkin Bag',
'Hermes',
'purple',
'bag',
'lg',
15470
);
const birkinButton = document.getElementById('birkin');
birkinButton.addEventListener('click', () => {
if (barbie.wallet >= birkin.price) {
barbie.wardrobe.push(birkin);
barbie.wallet -= birkin.price;
barbie.render();
// WE updated the wardrobe that belongs to barbie so the object was changed
// the object control the information that is visible to us on the screen
// I want to re-render the content so that i can see the updated information in the browser
} else {
alert('Stop trippin you know you aint got it like that');
}
});
const workButton = document.getElementById('work');
workButton.addEventListener('click', () => {
if (barbie.career) {
barbie.wallet += barbie.career.income; // WE updated the wallet that belongs to barbie so the object was changed
// the object control the information that is visible to us on the screen
// I want to re-render the content so that i can see the updated information in the browser
barbie.render();
} else {
alert('You are unemployed, get a job first');
}
});
barbie.render();