Skip to content

Commit 91ec8ca

Browse files
committed
passed tests
1 parent 471be76 commit 91ec8ca

5 files changed

Lines changed: 79 additions & 10 deletions

File tree

.DS_Store

6 KB
Binary file not shown.

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(potentialPassword) {
17+
return this.password === potentialPassword;
18+
}
19+
}
1120

1221
// Part 2
1322
// Create a class called `Animal` and a class called `Cat` using ES6 classes.
@@ -20,6 +29,24 @@
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+
return ++this.age;
38+
}
39+
}
40+
41+
class Cat extends Animal {
42+
constructor(options) {
43+
super(options);
44+
this.name = options.name;
45+
}
46+
meow() {
47+
return `${this.name} meowed!`;
48+
}
49+
}
2350

2451
/* eslint-disable no-undef */
2552

src/prototype.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
12
/*
23
Object oriented design is commonly used in video games. For this part of the assignment
34
you will be implementing several classes with their correct inheritance heirarchy.
@@ -48,6 +49,38 @@
4849
hamsterHuey.takeDamage(); // returns 'Hamster Huey took damage.'
4950
hamsterHuey.destroy(); // returns 'Game object was removed from the game.'
5051
*/
52+
class GameObject {
53+
constructor(objAttr) {
54+
this.createdAt = objAttr.createdAt;
55+
this.dimensions = objAttr.dimensions;
56+
}
57+
destroy() {
58+
const name = this.name;
59+
return 'Game object was removed from the game.';
60+
}
61+
}
62+
class NPC extends GameObject {
63+
constructor(npcAttr) {
64+
super(npcAttr);
65+
this.hp = npcAttr.hp;
66+
this.name = npcAttr.name;
67+
}
68+
takeDamage() {
69+
return `${this.name} took damage.`;
70+
}
71+
}
72+
73+
class Humanoid extends NPC {
74+
constructor(humAttr) {
75+
super(humAttr);
76+
this.faction = humAttr.faction;
77+
this.weapons = humAttr.weapons;
78+
this.language = humAttr.language;
79+
}
80+
greet() {
81+
return `${this.name} offers a greeting in ${this.language}.`;
82+
}
83+
}
5184

5285
/* eslint-disable no-undef */
5386

src/recursion.js

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ const nFibonacci = (n) => {
44
// fibonacci sequence: 1 1 2 3 5 8 13 ...
55
// return the nth number in the sequence
66
if (n <= 1) {
7-
return 1;
7+
return n;
88
}
9-
return nFibonacci(n - 1) + nFibonacci(n - 2);
9+
return nFibonacci(n - 2) + nFibonacci(n - 1);
1010
};
1111

1212
const nFactorial = (n) => {
@@ -22,6 +22,19 @@ const nFactorial = (n) => {
2222
const checkMatchingLeaves = (obj) => {
2323
// return true if every property on `obj` is the same
2424
// otherwise return false
25+
// make a list of the values in obj
26+
const values = [];
27+
const getValues = (object) => {
28+
Object.values(object).forEach((value) => {
29+
if (Object(value) === value) {
30+
getValues(value);
31+
} else {
32+
values.push(value);
33+
}
34+
});
35+
};
36+
getValues(obj);
37+
return values.every(x => x === values[0]);
2538
};
2639

2740
/* eslint-enable no-unused-vars */

src/this.js

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@ const me = new User({
2525

2626
const result = me.checkPassword('correcthorsebatterystaple'); // should return `true`
2727

28-
console.log(result);
29-
3028
/* part 2 */
3129

3230
const checkPassword = function comparePasswords(passwordToCompare) {
@@ -42,17 +40,15 @@ const checkPassword = function comparePasswords(passwordToCompare) {
4240

4341
// .call
4442

45-
console.log(checkPassword.call(me, 'correcthorsebatterystaple'));
46-
console.log(checkPassword.call(me, 'wrongpassword'));
43+
checkPassword.call(me, 'correcthorsebatterystaple');
44+
checkPassword.call(me, 'wrongpassword');
4745

4846
// .apply
4947

50-
console.log(checkPassword.apply(me, ['correcthorsebatterystaple']));
51-
console.log(checkPassword.apply(me, ['wrongpassword']));
48+
checkPassword.apply(me, ['correcthorsebatterystaple']);
49+
checkPassword.apply(me, ['wrongpassword']);
5250

5351
// .bind
5452

5553
const isTrue = checkPassword.bind(me, 'correcthorsebatterystaple');
5654
const isFalse = checkPassword.bind(me, 'wrongpassword');
57-
console.log(isTrue());
58-
console.log(isFalse());

0 commit comments

Comments
 (0)