Test Case Bug - Make a Person

Hi there,

I’m having trouble to submit a correct code on one of the problems. it is “Make a Person” under “Advanced Algorithm Scripting”.

The test case that returns false is "bob.getFullName() should return “Haskell Curry” after bob.setLastName(“Curry”). "

I tested my code outside freeCodeCamp and it works on each test case. Could you help me with this problem please?

My code:


var Person = function(firstAndLast) {
    // Complete the method below and implement the others similarly
  
  this.getFirstName = function() {
    return firstAndLast.split(' ')[0];
  };
  
  this.getLastName = function() {
    return firstAndLast.split(' ')[1];
  };
  
  this.getFullName = function() {
    return firstAndLast;
  };
  
  this.setFirstName = function(firstName) {
    bob = new Person(firstName + " " + this.getLastName());
  };
  
  this.setLastName = function(lastName) {
    bob = new Person(this.getFirstName() + " " + lastName);
  };
  
  this.setFullName = function(fullName) {
    bob = new Person(fullName);
  };
    
};

var bob = new Person('Bob Ross');

You shouldn’t be creating a new Person in your setter functions.

1 Like

Thanks for taking your time for this! Solved by simply keeping first and last names in an array. What was I thinking?