1+ // Check again for last part**
2+
13// Follow the instructions and fill in the blank sections.
24// There are no tests for this file.
35// To verify your code works you can run this file using `node this.js` while in the `/src` folder
79class User {
810 constructor ( options ) {
911 // set a username and password property on the user object that is created
12+ this . username = options . username ;
13+ this . password = options . password ;
1014 }
1115 // create a method on the User class called `checkPassword`
1216 // this method should take in a string and compare it to the object's password property
1317 // return `true` if they match, otherwise return `false`
18+ checkPassword ( passwordToCompare ) {
19+ return this . password === passwordToCompare ;
20+ }
1421}
15-
1622const me = new User ( {
1723 username : 'LambdaSchool' ,
1824 password : 'correcthorsebatterystaple' ,
1925} ) ;
2026
2127const result = me . checkPassword ( 'correcthorsebatterystaple' ) ; // should return `true`
28+ console . log ( result ) ;
29+
2230
2331/* part 2 */
2432
@@ -27,13 +35,19 @@ 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
3241// invoke `checkPassword` on `me` by explicitly setting the `this` context
3342// use .call, .apply, and .bind
3443
3544// .call
45+ checkPassword . call ( me , 'correcthorsebatterystaple' ) ;
3646
3747// .apply
48+ checkPassword . apply ( me , 'correcthorsebatterystaple' ) ;
3849
3950// .bind
51+ const boundedCheck = checkPassword . bind ( me ) ;
52+ boundedCheck ( 'correcthorsebatterystaple' ) ;
53+
0 commit comments