Skip to content

Commit 6ce12c3

Browse files
committed
Completed this.js
1 parent c9dd27c commit 6ce12c3

2 files changed

Lines changed: 17 additions & 3 deletions

File tree

src/prototype.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@
66
GameObject
77
createdAt
88
dimensions
9-
destroy() // prototype method -> returns the string 'Game object was removed from the game.'
9+
destroy() // prototype method -> returns the string 'Game object was removed from the game.' */
10+
11+
/*
1012
1113
NPC
1214
hp

src/this.js

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,26 @@
77
class User {
88
constructor(options) {
99
// set a username and password property on the user object that is created
10+
this.username = options.username;
11+
this.password = options.password;
1012
}
13+
/*
14+
checkPassword(pass) {
15+
return pass === this.password;
16+
}
17+
1118
// create a method on the User class called `checkPassword`
1219
// this method should take in a string and compare it to the object's password property
1320
// return `true` if they match, otherwise return `false`
1421
}
15-
22+
*/
23+
}
1624
const me = new User({
1725
username: 'LambdaSchool',
1826
password: 'correcthorsebatterystaple',
1927
});
2028

21-
const result = me.checkPassword('correcthorsebatterystaple'); // should return `true`
29+
// const result = me.checkPassword('correcthorsebatterystaple'); // should return `true`
2230

2331
/* part 2 */
2432

@@ -27,8 +35,12 @@ const checkPassword = function comparePasswords(passwordToCompare) {
2735
// use `this` to access the object's `password` property.
2836
// do not modify this function's parameters
2937
// note that we use the `function` keyword and not `=>`
38+
return this.password === passwordToCompare;
3039
};
3140

41+
User.prototype.checkPassword = checkPassword;
42+
console.log(me.checkPassword('correcthorsebatterystaple'));
43+
3244
// invoke `checkPassword` on `me` by explicitly setting the `this` context
3345
// use .call, .apply, and .bind
3446

0 commit comments

Comments
 (0)