Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 40 additions & 19 deletions practice.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
//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
//To specify that the current variable is what is the actual variable inside that scope i think

// 2) What are the four rules that govern what the 'this keyword' is bound to and describe each?

//Answer
//when in global the value of this is the actual window value
//using dot preceded when calling a function
//when in constructor the value of this is what is being returned
//when used call/apply this is explcit

// 3) What does .bind do?

//Answer
//it encloses the function so its variables inside can be passed to other i think


//Next Problem
Expand All @@ -19,18 +22,33 @@
//email --> which is a string
//getUsername --> which is a function that returns the current object's username property. *Don't use 'user' instead use the 'this' keyword*

//Code Here
let user = new Object();
user = {
username: "Benny",
email: "benny@boom.camp",
getUsername: function() {return this.username;}
}

//Code Here

//Now, invoke the getUsername method and verify you got the username of the object and not anything else.

user.getUsername();

//Next Problem


// Write a constructor function, including method definitions, which will make the following function invocations function properly.

//Function Invocations Here

//Function Invocations Here
function Car(brand,name,year){
let move = 0;
return {
moveCar(){
return move + 10;
}
}
}
var prius = new Car('Toyota', 'Prius', 2011);
var mustang = new Car('Ford', 'Mustang', 2013);

Expand All @@ -44,41 +62,44 @@ mustang.moveCar(); //increments mustang' move property by 10. Returns the new mo
//Continuation of previous problem

var getYear = function(){
return this.year;
return this.year;
};

// Above you are given a getYear function. Use the bind function to bind the prius object to the function and save it in a variable called getPriusYear
// Then use the bind function to bind the mustang to the function and save it in a varabile called getMustangYear
// Console Log the results of the getPriusYear and getMustangYear to see that they are returning the correct years.


let getPriusYear = getYear.bind(prius);
let getMustangYear = getYear.bind(mustang);
//Note(no tests)
//Code Here
//Code Here



//New Problem

var myUser = {
username: 'iliketurtles',
age: 13,
email: 'iliketurtles@gmail.com'
username: 'iliketurtles',
age: 13,
email: 'iliketurtles@gmail.com',
getMyUsername: function() {
return this.username;
}
};

var getMyUsername = function() {
return this.username;
};

var userName = getMyUsername(); //Fix this

var userName = myUser.getMyUsername(); //Fix this

//Above you're given an object, and a function. What will the getMyUsername function return?
//Note(no tests)
//Answer Here
//Answer Here
//the username of the user which is iliketurtles

//In the example above, what is the 'this keyword' bound to when getMyUsername runs?

//Answer Here
//Answer Here
//username


//Fix the getMyUsername invocation (stored in the userName variable, at the bottom of the above code) so that userName will be equal to 'iliketurtles'.

4 changes: 2 additions & 2 deletions user.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"name": "",
"email": ""
"name": "John Paul Garcia",
"email": "john.garcia@boom.camp"
}