Link to the challenge: https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/make-a-person
So getters are working fine.
However the setters are not working. When I call bob.setFirstName(“Haskell”) it doesn´t change anything to firstAndLast. why just doing firstAndLast = “first” doesn´t change anything. (because after all firstAndLast does have a place in memory and it should work as a “variable” right? If not i´m out of ideas how to modify this things withouth being able to create variables)
var Person = function(firstAndLast) {
this.getFullName = firstAndLast;
this.getLastName = firstAndLast.slice(firstAndLast.lastIndexOf(" "), ).slice(1,)
this.getFirstName = firstAndLast.slice(0 , firstAndLast.lastIndexOf(" "));
this.setFullName = function(name){firstAndLast = name }
this.setFirstName = function(first){
//firstAndLast.replace((firstAndLast.slice(firstAndLast.lastIndexOf(" "), ).slice(1,)), first)
firstAndLast = "first"
};
this.setLastName = function(last){(firstAndLast.slice(0 , firstAndLast.lastIndexOf(" "))) = last};
};
var bob = new Person('Bob Ross');
bob.setFirstName("Haskell")
bob.getFullName; // still Returns Bob Ross