Person Constructor

Completed Code

function Person(firstName, lastName, gender, age, birthday) {
    this.firstName = firstName;
    this.lastName = lastName;
    this.gender = gender;
    this.age = age;
    this.birthday = birthday;
    this.nextYear = this.age + 1;
    this.fullName = function () {
        return (this.firstName + " " + this.lastName);
    };
    this.pronoun = function () {
        if (this.gender.toLowerCase() === 'male') {
            return "He";
        } else if (this.gender.toLowerCase() === 'female') {
            return "She";
        } else {
            return "They";
        }
    };
    this.possessive = function () {
        if (this.gender.toLowerCase() === 'male') {
            return "his";
        } else if (this.gender.toLowerCase() === 'female') {
            return "her";
        } else {
            return "their";
        }
    };
    this.ordinalSuffix = function (i) {
        var j = i % 10,
            k = i % 100;
        if (j == 1 && k != 11) {
            return i + "st";
        }
        if (j == 2 && k != 12) {
            return i + "nd";
        }
        if (j == 3 && k != 13) {
            return i + "rd";
        }
        return i + "th";
    };
}

var person1 = new Person('Bob', 'Smith', 'male', 35, 'March 4');
console.log(person1);
console.log(person1.fullName());
console.log(person1.pronoun());
console.log(person1.nextYear);
console.log(person1.ordinalSuffix(person1.age));

Output

Person {
  firstName: 'Bob',
  lastName: 'Smith',
  gender: 'male',
  age: 35,
  birthday: 'March 4',
  nextYear: 36,
  fullName: [Function],
  pronoun: [Function],
  possessive: [Function],
  ordinalSuffix: [Function] }

Bob Smith
He
36
35th

We'll look at all of this in the next section.

Last updated