Algorithm Scripting: Make a Person

Algorithm Scripting: Make a Person
0.0 0

#1

Tell us what’s happening:
I pass all the tests except the object.keys.

I have no clue how to do this without setting this.name.

Your code so far


var Person = function(firstAndLast) {
  // Complete the method below and implement the others similarly
  this.name = firstAndLast.split(' ');
  
  this.getFirstName = function() {
    return this.name[0];
  }
  this.getLastName = function() {
    return this.name[1];
  }
  this.getFullName = function() {
    return this.name.join(' ');
  };
  this.setFirstName = function(first) {
    this.name[0] = first;
  }
  this.setLastName = function(last) {
    this.name[1] = last;
  }
  this.setFullName = function(firstAndLast) {
    this.name = firstAndLast.split(' ');
  }
  
};

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



Your browser information:

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

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


#2

Look closely at how you set the values. You are repeating yourself somewhere. There’s a way to reuse a function somewhere.


#3

Ok i managed… used a var name instead of this.name.