Tell us what’s happening:
why my code shown below works well except Object.keys(bob).length returns 7.
However, if I replace this.firstAndLast with fullName, it works perfectly (Object.keys(bob).length returns 6).
Can anyone explain this difference. It seems work in Java.
Your code so far
var Person = function(firstAndLast) {
// Complete the method below and implement the others similarly
this.firstAndLast = firstAndLast;
// define getter and setter
this.getFullName = function() {
return this.firstAndLast;
};
this.setFullName = function(firstAndLast){
this.firstAndLast = firstAndLast;
};
this.getFirstName = function() {
return this.firstAndLast.split(" ")[0];
};
this.setFirstName = function(firstName){
this.firstAndLast = firstName + " " + this.firstAndLast.split(" ")[1];
};
this.getLastName = function() {
return this.firstAndLast.split(" ")[1];
};
this.setLastName = function(lastName){
this.firstAndLast = this.firstAndLast.split(" ")[0] + " " + lastName;
};
};
var bob = new Person("Bob Ross");
bob.getFullName();
Your browser information:
Your Browser User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.84 Safari/537.36
.
Link to the challenge: