Tell us what’s happening:
Gone back and forth on this so many times I can’t figure out why it isn’t being accepted.
All my test runs match the expected output in the tests but no dice.
Your code so far
//
// Fill in the object constructor with the following methods below:
//
// getFirstName()
// getLastName()
// getFullName()
// setFirstName(first)
// setLastName(last)
// setFullName(firstAndLast)
// Run the tests to see the expected output for each method.
// The methods that take an argument must accept only one argument
// and it has to be a string. These methods must be the only available
// means of interacting with the object.
var Person = function(firstAndLast) {
// Complete the method below and implement the others similarlyN
const name = firstAndLast.split(' ');
let firstName = name[0];
let lastName = name[1];
this.getFirstName = function() {
return firstName;
};
this.getLastName = function() {
return lastName;
}
this.getFullName = function() {
return firstName + " " + lastName;
}
this.setFirstName = function(fName) {
firstName = fName;
}
this.setLastName = function(lName) {
lastName = lName;
}
this.setFullName = function(fulName) {
firstAndLast = fulName;
}
};
var bob = new Person('Bob Ross');
console.log(bob.getFirstName());
bob.setFirstName("Haskell");
console.log(bob.getFirstName());
console.log(bob.getFullName());
bob.setLastName("Curry");
console.log(bob.getFullName());
console.log(bob.getFirstName());
console.log(bob.getLastName());
Your browser information:
User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.138 Safari/537.36.
I think you need to remove all the set methods calls you have, as the tests are testing the bob object created in the challenge
edit: and as @kerafyrm say you have setFullName not doing what you want (you are not updating variables firstName and lastName)
@JeremyLT: do you want to create an issue on github for this? it seems an unnecessary headache
It’s great that you know how to do this, but we prefer to help users develop their own code rather than giving them solutions. Thanks for understanding.
You have in your setFullName a reference to a variable that does not exist. firstAndLast isn’t in your object, as you have set it up. You should instead use the same logic as your constructor and use the two variables you have, firstName and lastName.
Please let me know if I can be clearer.
After than, you’ll want to remove all of the code after var bob = new Person("Bob Ross") ;