Make a Person new

Please help !!! I can not understand why some tests do not pass


var Person = function(firstAndLast) {
  // Complete the method below and implement the others similarly
  let inputData = firstAndLast.match( /\w+/ig );
  let firstName = inputData[0];
  let lastName = inputData[1];
  let fullName = firstName + " " + lastName;


  this.getFirstName = function() {
    return firstName;
  };
  this.getLastName = function() {
    return lastName;
  };
  this.getFullName = function() {
    return fullName;
  };
  this.setFirstName = function(setFirstName) {
    return firstName = setFirstName;
  };
  this.setLastName = function(setLastName) {
    return lastName = setLastName;
  };
  this.setFullName = function(setFullName) {
    let arrSetFullName = setFullName.match( /\w+/ig );
    return fullName = arrSetFullName.join(" ");
  };
  return firstAndLast;
};

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

bob.getFullName();

Your browser information:

User Agent is: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.140 Safari/537.36.

Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/make-a-person

When you are setting firstnames and lastnames, you need to also update your fullname.

1 Like

I changed the code a little bit, but I haven’t passed two tests yet.

bob.getFullName() should return “Haskell Curry” after bob.setFullName("Haskell Curry") .
bob.getLastName() should return “Curry” after bob.setFullName("Haskell Curry") .

var Person = function(firstAndLast) {
  // Complete the method below and implement the others similarly
  let inputData = firstAndLast.match( /\w+/ig );
  let firstName = inputData[0];
  let lastName = inputData[1];
  let fullName;

  this.getFirstName = function() {
    return firstName;
  };
  this.getLastName = function() {
    return lastName;
  };
  this.getFullName = function() {
    return fullName = firstName + " " + lastName;
  };
  this.setFirstName = function(first) {
    return firstName = first;
  };
  this.setLastName = function(last) {
    return lastName = last;
  };
  this.setFullName = function(firstAndLast) {
    let arrSetFullName = firstAndLast.match( /\w+/ig );
    return fullName = arrSetFullName.join(" ");
  };
  return firstAndLast;
};

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

bob.getFullName();```

Your setFirstName and setLastName methods shouldn’t return anything. That’s the purpose of your get methods. They are literally setting/updating values in your constructor. When you are updating either first/last name make sure to update fullName as well because fullName will always change if firstName or lastName changes.

1 Like

Many thanks for the advice. Happened