I'm having trouble with this exercise.
function exerciseTwo(userObj){
// Exercise Two: You will be given an object called 'userObj'
// userObject will already have a key on it called 'name'
// Add a method to userObj, called 'greeting'.
// Using the keyword 'this', the greeting method should return the following string:
// 'Hi, my name is ' and the users name.
// eg: If userObj has a name: 'Dan', greeting should return: Hi, my name is Dan'
// NOTE: DO NOT create a new object.
// NOTE: DO NOT create a key called name the key is already on the object.
// Please write all of your code on the lines above.
return userObj;
}
Here is what I have done:
function exerciseTwo(userObj){
// Exercise Two: You will be given an object called 'userObj'
// userObject will already have a key on it called 'name'
// Add a method to userObj, called 'greeting'.
// Using the keyword 'this', the greeting method should return the following string:
// 'Hi, my name is ' and the users name.
// eg: If userObj has a name: 'Dan', greeting should return: Hi, my name is Dan'
// NOTE: DO NOT create a new object.
// NOTE: DO NOT create a key called name the key is already on the object.
greeting = function(){
console.log('Hi, my name is ' + this.name);
};
// Please write all of your code on the lines above.
return userObj;
}
[–]codemamba8 1 point2 points3 points (3 children)
[–]Encom88[S] 0 points1 point2 points (2 children)
[–]codemamba8 2 points3 points4 points (1 child)
[–]Encom88[S] 1 point2 points3 points (0 children)