Skip to content

Commit 7214c92

Browse files
authored
this homework done
1 parent 5136e02 commit 7214c92

1 file changed

Lines changed: 41 additions & 31 deletions

File tree

‎src/this.js‎

Lines changed: 41 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,41 @@
1-
// Follow the instructions and fill in the blank sections.
2-
// There are no tests for this file.
3-
// To verify your code works you can run this file using `node this.js` while in the `/src` folder
4-
5-
class User {
6-
constructor(options) {
7-
// set a username and password property on the user object that is created
8-
}
9-
// create a method on the User class called `checkPassword`
10-
// this method should take in a string and compare it to the object's password property
11-
// return `true` if they match, otherwise return `false`
12-
}
13-
14-
const me = new User({ username: 'LambdaSchool', password: 'correcthorsebatterystaple' });
15-
const result = me.checkPassword('correcthorsebatterystaple'); // should return `true`
16-
17-
const checkPassword = function comparePasswords(passwordToCompare) {
18-
// recreate the `checkPassword` method that you made on the `User` class
19-
// use `this` to access the object's `password` property.
20-
// do not modify this function's parameters
21-
// note that we use the `function` keyword and not `=>`
22-
};
23-
24-
// invoke `checkPassword` on `me` by explicitly setting the `this` context
25-
// use .call, .apply, and .bind
26-
27-
// .call
28-
29-
// .apply
30-
31-
// .bind
1+
// Follow the instructions and fill in the blank sections.
2+
// There are no tests for this file.
3+
// To verify your code works you can run this file using `node this.js` while in the `/src` folder
4+
5+
class User {
6+
constructor(options) {
7+
// set a username and password property on the user object that is created
8+
this.username = options.username;
9+
this.password = options.password;
10+
}
11+
// create a method on the User class called `checkPassword`
12+
// this method should take in a string and compare it to the object's password property
13+
// return `true` if they match, otherwise return `false`
14+
checkPassword(password) {
15+
return this.password === password;
16+
}
17+
}
18+
19+
const me = new User({ username: 'LambdaSchool', password: 'correcthorsebatterystaple' });
20+
const result = me.checkPassword('correcthorsebatterystaple'); // should return `true`
21+
console.log(result);
22+
23+
const checkPassword = function comparePasswords(passwordToCompare) {
24+
// recreate the `checkPassword` method that you made on the `User` class
25+
// use `this` to access the object's `password` property.
26+
// do not modify this function's parameters
27+
// note that we use the `function` keyword and not `=>`
28+
return this.password === passwordToCompare;
29+
};
30+
31+
console.log(checkPassword("blorp"));
32+
// invoke `checkPassword` on `me` by explicitly setting the `this` context
33+
// use .call, .apply, and .bind
34+
35+
// .call
36+
checkPassword.call(me, 'correcthorsebatterystaple');
37+
38+
// .apply
39+
checkPassword.apply(me, ['correcthorsebatterystaple']);
40+
// .bind
41+
checkPassword.bind(me, 'correcthorsebatterystaple')();

0 commit comments

Comments
 (0)