For this problem I initially used this.first, this.last, this.fullName which didn’t pass the test. It was when I made variables out of first, last and fullName did I pass the challenge.
I am still unsure why it didn’t work with this.first… I thought this.first would be considered a local variable first which is same as local variable let first?
I would appreciate if someone can please guide and clarify this. Thank you.
Make A person
var Person = function(firstAndLast) {
// Only change code below this line
// Complete the method below and implement the others similarly
let first = firstAndLast.split(" ")[0];
let last = firstAndLast.split(" ")[1];
let fullName = first + " " + last;
this.setFirstName = function(fName) {
first = fName;
}
this.setLastName = function(lName){
last = lName;
}
this.setFullName = function(fullName){
first = fullName.split(" ")[0];
last = fullName.split(" ")[1];
fullName = first + " " + last;
}
this.getFullName = function() {
return first + " " + last;
};
this.getFirstName = function(){
return first;
}
this.getLastName = function() {
return last;
}
return firstAndLast;
};
var bob = new Person('Bob Ross');
bob.setFirstName("Haskell");