Tell us what’s happening:
I would like to publish this in the Make a Person Guide, but when I try I receive a restraining message…
Your code so far
var Person = function(firstAndLast) {
this.getFullName = function() {
return firstAndLast;
};
this.getFirstName = function(){
const regex = /(\w+)(?=\s)/gi;
let firstName = firstAndLast.match(regex);
return firstAndLast.replace(firstAndLast, firstName);
}
this.getLastName = function(){
const regex = /(?<=\s)([\w\s\S]+)/gi;
let lastName = firstAndLast.match(regex);
return firstAndLast.replace(firstAndLast, lastName);;
}
this.setFullName = function setFullName(setFullName){
return firstAndLast = setFullName;
}
this.setFirstName = function setFirstName(first){
return firstAndLast = first + ' ' + this.getLastName();
}
this.setLastName = function setLastName(last){
return firstAndLast = this.getFirstName() + ' ' + last;
}
};
var bob = new Person('Bob Ross');
bob.getFullName();//Bob Ross
bob.setFirstName("Paulo");
bob.setLastName("León");
bob.getFullName();//Paulo León
Your browser information:
User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.163 Safari/537.36 OPR/67.0.3575.137
.
Challenge: Make a Person
Link to the challenge: