-3

I am watching a YouTube video about learning javascript from some years ago, and in the video the code seems to work except on my VScode.

Here is the code, could you please let me know what I might have missed out:

function Person(firstName, lastName, dob) {
    this.firstName = firstName;
    this.lastName = lastName;
    this.dob = new Date(dob);
    this.dateBio = function() {
        return `${this.dob.getFullYear}`
    }

}

Person.prototype.fullName = function() {
    return `${this.firstName} ${this.lastName}`
}

const person1 = new Person('James','Smith', '27 July 1967');
const person2 = new Person('Mary', 'Franklin', '5 November 1991')

console.log(person1.fullName)
Guerric P
  • 30,447
  • 6
  • 48
  • 86
The Future
  • 55
  • 1
  • 5

2 Answers2

5

you have logged function reference only, you need to call the function.

console.log(person1.fullName())
sasi66
  • 437
  • 2
  • 7
3

Well just display the result of the function after calling it, at the moment you display the function itself:

function Person(firstName, lastName, dob) {
    this.firstName = firstName;
    this.lastName = lastName;
    this.dob = new Date(dob);
    this.dateBio = function() {
        return `${this.dob.getFullYear}`
    }

}

Person.prototype.fullName = function() {
    return `${this.firstName} ${this.lastName}`
}

const person1 = new Person('James','Smith', '27 July 1967');
const person2 = new Person('Mary', 'Franklin', '5 November 1991')

console.log(person1.fullName())
Guerric P
  • 30,447
  • 6
  • 48
  • 86