Make a Person - Reference solution not working?

Tell us what’s happening:
I have tried multiple variations of solutions to satisfy all unit tests, and have continued to have several that fail. Eventually, I decided to check there reference solution to see what I have done wrong, to find that the reference solution matched my original solution.

I tried plugging in the reference solution and running the tests - it’s failing on the exact same tests, making me think there possibly is a problem with the tests themselves (which I agree seems unlikely). If you look at the code below, you will see my current solution commented out and the reference solution being used.

Could someone try to run the reference solution from: here and let me know if you get errors as well, or possibly tell me where my solution is failing?

Both give these results:
// running tests
bob.getFirstName() should return “Bob”.
bob.getLastName() should return “Ross”.
bob.getFullName() should return “Bob Ross”.
bob.getFullName() should return "Haskell Ross" after bob.setFirstName(“Haskell”)` .
// tests completed
// console output
First(Bob)
Last(Ross)
Full(Bob Ross)
Full(Haskell Curry)
First(Haskell) Last(Curry)

Your code so far


// var Person = function(firstAndLast) {
//   // Complete the method below and implement the others similarly
//   var firstName;
//   var lastName;

//   this.getFullName = function() {
//     return firstName + " " + lastName;
//   };
//   this.setFullName = function(firstAndLast){
//     if(typeof firstAndLast == "string"){
//       firstName = firstAndLast.split(" ")[0];
//       lastName = firstAndLast.split(" ")[1];
//     }
//   };
//   this.getFirstName = function(){
//     return firstName;
//   };
//   this.getLastName = function(){
//     return lastName;
//   };
//   this.setFirstName = function(name){
//     if(typeof first == "string") firstName = name;
//   };
//   this.setLastName = function(name){
//     if(typeof last == "string") lastName = name;
//   };
//   this.setFullName(firstAndLast);
// };

var Person = function(firstAndLast) {
var fullName = firstAndLast;

this.getFirstName = function() {
  return fullName.split(" ")[0];
};

this.getLastName = function() {
  return fullName.split(" ")[1];
};

this.getFullName = function() {
  return fullName;
};

this.setFirstName = function(name) {
  fullName = name + " " + fullName.split(" ")[1];
};

this.setLastName = function(name) {
  fullName = fullName.split(" ")[0] + " " + name;
};

this.setFullName = function(name) {
  fullName = name;
};
};

var bob = new Person("Bob Ross");
bob.getFullName();

console.log("First("+bob.getFirstName()+")");
console.log("Last("+bob.getLastName()+")");
console.log("Full("+bob.getFullName()+")");

bob.setFullName("Haskell Curry");
console.log("Full("+bob.getFullName()+")");
console.log("First("+bob.getFirstName()+")");
console.log("Last("+bob.getLastName()+")");


Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.61 Safari/537.36.

Challenge: Make a Person

Link to the challenge:

Removing the bob.setFullName("Haskell Curry"); code should make it pass.

Yup, that did the trick. I didn’t even think of looking at/removing my test calls to see if it was affecting the results - great catch!