Skip to content

Commit 9731331

Browse files
Completed JavaScript-II assignment
1 parent b170483 commit 9731331

3 files changed

Lines changed: 105 additions & 6 deletions

File tree

src/class.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,15 @@
88
// Return true if the potential password matches the `password` property. Otherwise return false.
99

1010
// code here
11+
class User {
12+
constructor(options) {
13+
this.email = options.email;
14+
this.password = options.password;
15+
}
16+
comparePasswords(entered) {
17+
return entered === this.password;
18+
}
19+
}
1120

1221
// Part 2
1322
// Create a class called `Animal` and a class called `Cat` using ES6 classes.
@@ -20,7 +29,25 @@
2029
// property set on the Cat instance.
2130

2231
// code here
32+
class Animal {
33+
constructor(options) {
34+
this.age = options.age;
35+
}
36+
growOlder() {
37+
this.age++;
38+
return this.age;
39+
}
40+
}
2341

42+
class Cat extends Animal {
43+
constructor(options) {
44+
super(options);
45+
this.name = options.name;
46+
}
47+
meow() {
48+
return `${this.name} meowed!`;
49+
}
50+
}
2451
/* eslint-disable no-undef */
2552

2653
module.exports = {

src/prototype.js

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,80 @@
4949
hamsterHuey.destroy(); // returns 'Game object was removed from the game.'
5050
*/
5151

52+
// function GameObject(attr) {
53+
// this.createdAt = attr.createdAt;
54+
// this.dimensions = attr.dimensions;
55+
// }
56+
57+
// GameObject.prototype.destroy = function () {
58+
// return 'Game object was removed from the game.';
59+
// };
60+
61+
// function NPC(npcAttrs) {
62+
// GameObject.call(this, npcAttrs);
63+
// this.hp = npcAttrs.hp;
64+
// this.name = npcAttrs.name;
65+
// }
66+
67+
// NPC.prototype = Object.create(GameObject.prototype);
68+
69+
// NPC.prototype.takeDamage = function () {
70+
// return `${this.name} took damage.`;
71+
// };
72+
73+
// function Humanoid(humanAttrs) {
74+
// NPC.call(this, humanAttrs);
75+
// this.faction = humanAttrs.faction;
76+
// this.weapons = humanAttrs.weapons;
77+
// this.language = humanAttrs.language;
78+
// }
79+
80+
// Humanoid.prototype = Object.create(NPC.prototype);
81+
82+
// Humanoid.prototype.greet = function () {
83+
// return `${this.name} offers a greeting in ${this.language}.`;
84+
// };
85+
86+
class GameObject {
87+
constructor(attrs) {
88+
this.createdAt = attrs.createdAt;
89+
this.dimensions = attrs.dimensions;
90+
}
91+
//This method was causing 'this expected' linter error.
92+
// destroy() {
93+
// return 'Game object was removed from the game.';
94+
// }
95+
}
96+
97+
GameObject.prototype.destroy = function () {
98+
return 'Game object was removed from the game.';
99+
};
100+
101+
class NPC extends GameObject {
102+
constructor(npcAttrs) {
103+
super(npcAttrs);
104+
this.hp = npcAttrs.hp;
105+
this.name = npcAttrs.name;
106+
}
107+
108+
takeDamage() {
109+
return `${this.name} took damage.`;
110+
}
111+
}
112+
113+
class Humanoid extends NPC {
114+
constructor(humanoidAttrs) {
115+
super(humanoidAttrs);
116+
this.faction = humanoidAttrs.faction;
117+
this.weapons = humanoidAttrs.weapons;
118+
this.language = humanoidAttrs.language;
119+
}
120+
121+
greet() {
122+
return `${this.name} offers a greeting in ${this.language}.`;
123+
}
124+
}
125+
52126
/* eslint-disable no-undef */
53127

54128
module.exports = {

src/this.js

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
class User {
88
constructor(options) {
99
// set a username and password property on the user object that is created
10-
this.username = options.user;
10+
this.username = options.username;
1111
this.password = options.password;
1212
}
1313
// create a method on the User class called `checkPassword`
@@ -18,11 +18,10 @@ class User {
1818
return false;
1919
}
2020
}
21+
const filler = { username: 'LambdaSchool',
22+
password: 'correcthorsebatterystaple' };
2123

22-
const me = new User({
23-
username: 'LambdaSchool',
24-
password: 'correcthorsebatterystaple',
25-
});
24+
const me = new User(filler);
2625

2726
const result = me.checkPassword('correcthorsebatterystaple'); // should return `true`
2827
// console.log(result);
@@ -47,7 +46,6 @@ const checkPassword = function comparePasswords(passwordToCompare) {
4746

4847
// .call
4948
// console.log(checkPassword.call(me, 'correcthorsebatterystaple'));
50-
5149
// .apply
5250
// console.log(checkPassword.apply(me, ['correcthorsebatterystaple']));
5351

0 commit comments

Comments
 (0)