I changed the code a little bit, but I haven’t passed two tests yet.
bob.getFullName() should return “Haskell Curry” after bob.setFullName("Haskell Curry") . bob.getLastName() should return “Curry” after bob.setFullName("Haskell Curry") .
var Person = function(firstAndLast) {
// Complete the method below and implement the others similarly
let inputData = firstAndLast.match( /\w+/ig );
let firstName = inputData[0];
let lastName = inputData[1];
let fullName;
this.getFirstName = function() {
return firstName;
};
this.getLastName = function() {
return lastName;
};
this.getFullName = function() {
return fullName = firstName + " " + lastName;
};
this.setFirstName = function(first) {
return firstName = first;
};
this.setLastName = function(last) {
return lastName = last;
};
this.setFullName = function(firstAndLast) {
let arrSetFullName = firstAndLast.match( /\w+/ig );
return fullName = arrSetFullName.join(" ");
};
return firstAndLast;
};
var bob = new Person('Bob Ross');
bob.getFullName();```
Your setFirstName and setLastName methods shouldn’t return anything. That’s the purpose of your get methods. They are literally setting/updating values in your constructor. When you are updating either first/last name make sure to update fullName as well because fullName will always change if firstName or lastName changes.
Adding to what @shimphillip has already said above, your getFullName involves the firstName and lastName variables, so if that is the case you coulld have your setFullName update the firstName and lastName variables.
@wayper Make sure on all your “set” methods you are not returning a value. Only your “get” methods should be returning a value. Lastly, since you are using firstName and lastName mostly in your Person function, I would get rid of the fullName variable all together and just use firstName and lastName to build the string to return for the getFullName method and then for the setFullName method, you would just need to set the firstName and lastName from the arrSetFullName array.
EDIT: Also, you don’t need the following line at the end because the methods take care of anything which needs to be returned.