Help with Introduction to Objects The this Keyword II


#1

So I was coding, and I noticed something inside of the module. It was telling me that in this example

let person = {
  name: 'David',
  age: 24 ,
  weekendAlarm: 'No alarms needed',
  weekAlarm: 'Alarm set to 7AM',
  sayHello: function() {
    if (this.name) {
      return 'Hello, my name is David'
    }
  },
  sayGoodbye() {
    return 'Goodbye!'
  },
};
	let friend = {
    name:'Eric',
  };
  friend.sayHello = person.sayHello;
console.log(friend.sayhello())

According to the lesson, friend’s name should be the one popping up. However, when I printed this…it just repeated ‘Hello, my name is David’ twice. It still marked it as green (bug possibly?) but i’d like to get some help and know what is the -right- way to enter this in for future reference. I’ll be moving on and continuing because most of that topic I seem to understand just fine.

EDIT: Here is the link to the exercise! https://www.codecademy.com/courses/learn-javascript-objects/lessons/objects/exercises/this-ii?action=resume_content_item&course_redirect=introduction-to-javascript


#2

If you have not yet resolved this, please post a link to the exercise so we are sure to be looking at the correct lesson. Thank you.


#3

Thank you for your response! I edited the post and included the link at the end!


#4

The name should be a variable else it will always return David.

sayHello: function () {
    return `Hello, my name is ${this.name}.`
},