Skip to content

Commit d44ff36

Browse files
committed
Completed Javascript-II however, prototype file has a couple checks not passed by the test. This is because it says that the children objects are not inheriting the GameObjects destroy funcion. This is probably caused because since the linter would not let me just have return string as a class method, i had to refer to at least one this. If you look at the code you will see what I mean. The this file was causing a lot of headaches in terms of linting and i couldnt figure it out. I had to comment the whole page out just to test the class and prototype files.
1 parent 760fc13 commit d44ff36

File tree

3 files changed

+25
-21
lines changed

3 files changed

+25
-21
lines changed

src/class.js

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,22 +13,22 @@ class User {
1313
this.email = options.email;
1414
this.password = options.password;
1515
}
16-
comparePasswords (potentialPassword) {
16+
comparePasswords(potentialPassword) {
1717
if (potentialPassword === this.password) {
1818
return true;
1919
}
2020
return false;
2121
}
2222
}
2323

24-
const account1 = new User ({
25-
26-
password: `llamallama1122`
24+
const account1 = new User({
25+
26+
password: 'llamallama1122',
2727
});
2828

29-
//to test I would probably do:
30-
//console.log(account1.comparePasswords(potentialPasswordInput));
31-
29+
// to test I would probably do:
30+
// console.log(account1.comparePasswords(potentialPasswordInput));
31+
//
3232
// Part 2
3333
// Create a class called `Animal` and a class called `Cat` using ES6 classes.
3434
// `Cat` should extend the `Animal` class.
@@ -45,16 +45,18 @@ class Animal {
4545
constructor(options) {
4646
this.age = options.age;
4747
}
48-
growOlder () {
48+
growOlder() {
4949
return ++this.age;
50+
}
5051
}
5152

5253
class Cat extends Animal {
5354
constructor(options) {
55+
super(options);
5456
this.name = options.name;
5557
}
56-
meow () {
57-
return `${this.name} meowed!`
58+
meow() {
59+
return `${this.name} meowed!`;
5860
}
5961
}
6062
/* eslint-disable no-undef */

src/prototype.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,12 @@ class GameObject {
1313
constructor(gameObjectParameters) {
1414
this.createdAt = gameObjectParameters.createdAt;
1515
this.dimensions = gameObjectParameters.dimensions;
16+
this.phrase = 'Game object was removed from the game';
1617
}
1718
destroy() {
18-
return `Game object was removed from the game`
19-
}
20-
}
19+
return this.phrase;
20+
} // reason why i created this.phrase to be used in destroy is that the linter wont let me run the test without having a this keyword inside of the method here..
21+
} // I've tried return 'Game object was removed from the game'; but it doesn't accept that.. this is why the children are not properly inheriting it.
2122

2223
/*
2324
NPC
@@ -34,7 +35,7 @@ class NPC extends GameObject {
3435
this.name = NPCParameters.name;
3536
}
3637
takeDamage() {
37-
return `${this.name} took damage.`
38+
return `${this.name} took damage.`;
3839
}
3940
}
4041

@@ -48,15 +49,15 @@ class NPC extends GameObject {
4849
// should inherit takeDamage() from NPC
4950
*/
5051

51-
class Humanoid extends GameObject {
52+
class Humanoid extends NPC {
5253
constructor(humanoidParameters) {
5354
super(humanoidParameters);
5455
this.faction = humanoidParameters.faction;
5556
this.weapons = humanoidParameters.weapons;
5657
this.language = humanoidParameters.language;
5758
}
5859
greet() {
59-
return `${this.name} offers a greeting in ${this.language}.`
60+
return `${this.name} offers a greeting in ${this.language}.`;
6061
}
6162
}
6263

src/this.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,29 +5,30 @@
55
/* part 1 */
66

77
class User {
8-
constructor(un,pw) {
8+
constructor(user, pass) {
99
// set a username and password property on the user object that is created
10-
this.username = un;
11-
this.password = pw;
10+
this.username = user;
11+
this.password = pass;
1212
this.checkPassword = function(inputPass) {
1313
if (inputPass === this.password) {
1414
return true;
1515
}
1616
return false;
1717
}
1818
}
19+
}
1920
// create a method on the User class called `checkPassword`
2021
// this method should take in a string and compare it to the object's password property
2122
// return `true` if they match, otherwise return `false`
22-
}
23+
2324

2425
const me = new User('LambdaSchool', 'correcthorsebatterystaple');
2526

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

2829
// node this.js says that me.checkPassword is not a function so it throws an error.. hmmmmm
2930

30-
console.log(result);
31+
return result();
3132

3233
/* part 2 */
3334

0 commit comments

Comments
 (0)