Make a Person
Fill in the object constructor with the following methods below:
getFirstName()
getLastName()
getFullName()
setFirstName(first)
setLastName(last)
setFullName(firstAndLast)
Run the tests to see the expected output for each method. The methods that take an argument must accept only one argument and it has to be a string. These methods must be the only available means of interacting with the object.
freeCodeCamp Challenge Guide: Make a Person
var Person = function (firstAndLast) {
// Only change code below this line
// Complete the method below and implement the others similarly
this.getFullName = function () {
return firstAndLast;
};
this.getLastName = function () {
return firstAndLast.split(' ').slice()[1];
};
this.getFirstName = function () {
return firstAndLast.split(' ').slice()[0];
};
this.setFirstName = function (first) {
firstAndLast = first + ' ' + firstAndLast.split(' ').slice()[1]
};
this.setLastName = function (last) {
firstAndLast = firstAndLast.split(' ').slice()[0] + " " + last
};
this.setFullName = function (full) {
firstAndLast = full
}
return firstAndLast;
};
var bob = new Person('Bob Ross');
console.log(
bob.getFullName(),
bob.getLastName(),
bob.getFirstName(),
bob.setFirstName("Haskell"),
bob.getFullName()
)