Tell us what’s happening:
Hi, everyone,
My code is running fine and passing all the tests.
However, I am wondering if there would be a way to avoid repeating var names = firstAndLast.split(' ');
inside this.setFullName
.
I guess I could make var names
be a function, but I can’t put my finger on how I could make that do what I want.
I’d appreciate your advice on this.
Thanks a lot!
Your code so far
var Person = function(firstAndLast) {
var names = firstAndLast.split(" ");
this.getFullName = function() {
return names.join(" ");
};
this.getFirstName = function() {
return names[0];
}
this.getLastName = function() {
return names[1];
}
this.setFirstName = function(first) {
names[0] = first;
}
this.setLastName = function(last) {
names[1] = last;
}
this.setFullName = function(firstAndLast) {
var names = firstAndLast.split(' ');
this.setFirstName(names[0]);
this.setLastName(names[1]);
return this.getFullName;
}
return firstAndLast;
};
var bob = new Person('Bob Ross');
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.100 Safari/537.36
.
Link to the challenge: