From f649bd208d973bf52976a4afcbe94c795e88dd57 Mon Sep 17 00:00:00 2001 From: Jules Date: Mon, 27 May 2019 12:24:47 +0800 Subject: [PATCH 1/8] add details --- user.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/user.json b/user.json index 4ac80a0..3d7a607 100644 --- a/user.json +++ b/user.json @@ -1,4 +1,4 @@ { - "name": "", - "email": "" + "name": "Jules Ballaran", + "email": "jules.ballaran@boom.camp" } From 24c1d5da5d49bc94f3b81e27cb3ca4954e09615f Mon Sep 17 00:00:00 2001 From: Jules Date: Mon, 27 May 2019 12:33:52 +0800 Subject: [PATCH 2/8] user problem done --- practice.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/practice.js b/practice.js index c5812b5..4ef439f 100644 --- a/practice.js +++ b/practice.js @@ -20,9 +20,15 @@ //getUsername --> which is a function that returns the current object's username property. *Don't use 'user' instead use the 'this' keyword* //Code Here - + var user = { + username : 'jules.ballaran', + email : 'jules.ballaran@boom.camp', + getUsername(){ + return this.username; + } + }; //Now, invoke the getUsername method and verify you got the username of the object and not anything else. - +console.log(user.getUsername()); //Next Problem From d643202e738588e7e1f476bdb9996543970a9b39 Mon Sep 17 00:00:00 2001 From: Jules Date: Mon, 27 May 2019 12:56:43 +0800 Subject: [PATCH 3/8] user problem done --- practice.js | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/practice.js b/practice.js index 4ef439f..77e547d 100644 --- a/practice.js +++ b/practice.js @@ -40,12 +40,21 @@ console.log(user.getUsername()); var prius = new Car('Toyota', 'Prius', 2011); var mustang = new Car('Ford', 'Mustang', 2013); -//Hint, you'll need to add a move property, with a starting value of zero, and write a moveCar function which will increment the move property by 10. The move property will be added to every object that is being returned from the Car function. You'll also need to use the 'this' keyword properly in order to make sure you're invoking moveCar on the right object (prius vs mustang). +//Hint, you'll need to add a move property, with a starting value of zero, and write a moveCar function which will increment the move property by 10. +//The move property will be added to every object that is being returned from the Car function. You'll also need to use the 'this' keyword properly in +//order to make sure you're invoking moveCar on the right object (prius vs mustang). prius.moveCar(); //increments prius' move property by 10. Returns the new move property. mustang.moveCar(); //increments mustang' move property by 10. Returns the new move property. +//Car.prototype.moveCar = +function Car(brand, name, year){ + this.brand = brand; + this.name = name; + this.year = year; + this.move = 0; +} //Continuation of previous problem @@ -72,6 +81,7 @@ var myUser = { }; var getMyUsername = function() { + console.log(this); return this.username; }; @@ -80,11 +90,11 @@ var userName = getMyUsername(); //Fix this //Above you're given an object, and a function. What will the getMyUsername function return? //Note(no tests) //Answer Here - + //undefined function //In the example above, what is the 'this keyword' bound to when getMyUsername runs? //Answer Here - + // //Fix the getMyUsername invocation (stored in the userName variable, at the bottom of the above code) so that userName will be equal to 'iliketurtles'. From ac951fff419189a3807b92e2b19a9043686ddd8d Mon Sep 17 00:00:00 2001 From: Jules Date: Mon, 27 May 2019 13:04:22 +0800 Subject: [PATCH 4/8] car problem done --- practice.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/practice.js b/practice.js index 77e547d..e29337b 100644 --- a/practice.js +++ b/practice.js @@ -44,11 +44,13 @@ var mustang = new Car('Ford', 'Mustang', 2013); //The move property will be added to every object that is being returned from the Car function. You'll also need to use the 'this' keyword properly in //order to make sure you're invoking moveCar on the right object (prius vs mustang). +Car.prototype.moveCar = function(){ + return this.move += 10; +} + prius.moveCar(); //increments prius' move property by 10. Returns the new move property. mustang.moveCar(); //increments mustang' move property by 10. Returns the new move property. -//Car.prototype.moveCar = - function Car(brand, name, year){ this.brand = brand; this.name = name; From 5f0d13024f5242cf23ce005069e901f09f1d69e4 Mon Sep 17 00:00:00 2001 From: Jules Date: Mon, 27 May 2019 13:16:18 +0800 Subject: [PATCH 5/8] myUser problem done --- practice.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/practice.js b/practice.js index e29337b..59cd0ed 100644 --- a/practice.js +++ b/practice.js @@ -73,7 +73,6 @@ var getYear = function(){ //Code Here - //New Problem var myUser = { @@ -83,8 +82,7 @@ var myUser = { }; var getMyUsername = function() { - console.log(this); - return this.username; + return myUser.username; }; var userName = getMyUsername(); //Fix this From 3567efd3b6cce75e0cc252cb24e89adad68f35ce Mon Sep 17 00:00:00 2001 From: Jules Date: Mon, 27 May 2019 14:20:35 +0800 Subject: [PATCH 6/8] bind done --- practice.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/practice.js b/practice.js index 59cd0ed..f3f8bca 100644 --- a/practice.js +++ b/practice.js @@ -1,6 +1,6 @@ //We're in a job interview. Answer the following questions (try to not look at your notes unless you have to). // 1) What is the purpose of the 'this keyword'? - + //Answer // 2) What are the four rules that govern what the 'this keyword' is bound to and describe each? @@ -71,8 +71,10 @@ var getYear = function(){ //Note(no tests) //Code Here - - + var getPriusYear = getYear.bind(prius); + console.log(getPriusYear()); + var getMustangYear = getYear.bind(mustang); + console.log(getMustangYear()); //New Problem var myUser = { From afc4a9ece74b55e8208404ddfdd38c15d605c947 Mon Sep 17 00:00:00 2001 From: Jules Date: Mon, 27 May 2019 14:26:25 +0800 Subject: [PATCH 7/8] interview done --- practice.js | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/practice.js b/practice.js index f3f8bca..7511d8b 100644 --- a/practice.js +++ b/practice.js @@ -1,16 +1,19 @@ //We're in a job interview. Answer the following questions (try to not look at your notes unless you have to). // 1) What is the purpose of the 'this keyword'? - - //Answer + //Answer + //reference to properties in object // 2) What are the four rules that govern what the 'this keyword' is bound to and describe each? //Answer - + //default + //implicit + //explicit + //new // 3) What does .bind do? //Answer - + //creates new function //Next Problem From c5fec486d6f274b2d59b821850de6c4367a250d5 Mon Sep 17 00:00:00 2001 From: Jules Date: Mon, 27 May 2019 14:28:44 +0800 Subject: [PATCH 8/8] questions on getMyUsername --- practice.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/practice.js b/practice.js index 7511d8b..ee6c64e 100644 --- a/practice.js +++ b/practice.js @@ -99,7 +99,7 @@ var userName = getMyUsername(); //Fix this //In the example above, what is the 'this keyword' bound to when getMyUsername runs? //Answer Here - // + //getMyUsername properties //Fix the getMyUsername invocation (stored in the userName variable, at the bottom of the above code) so that userName will be equal to 'iliketurtles'.