Make a person - seeking some advice on direction to go in

`Tell us what’s happening:

I pass the first 6 tests but I am pretty sure I am doing it the wrong way. To pass the get first name I am just returning the argument

To pass the get first name and get last name I am just splitting the firstandlast string into two parts and returning the first past as first name and last part as last name.

I thought perhaps I should be reading documentation on getters and setters, please let me know if I should not or whether should clear all code and start again

Your code so far


var Person = function(firstAndLast) {
 // Complete the method below and implement the others similarly
 this.getFullName = function() {
return firstAndLast;
 };


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

var test = this.getFirstName


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

this.setLastName = function() {
   return firstAndLast.split(" ")[1];
 };

this.setFirstName = function() {
   return firstAndLast.split(" ")[0];
 };

this.setFullName = function() {
   return firstAndLast;
 };


 return firstAndLast;
};




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

Your browser information:

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

Challenge: Make a Person

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

One of the tests you are failing is as follows:

bob.getFullName() should return “Haskell Ross” after bob.setFirstName("Haskell")

You are failing because instead of “setting” the firstName you are simply splitting the original name which was passed into the function when the person was first created. This method will always return “Bob” as the first name.

One approach is to create local variables for first and last names and reference them when “getting” values and assign them new values when “setting”.

See if you can rethink your solution to incorporate what I describe.

Thanks for the response Randell ! I will work on that and rewrite my solution

Keep in mind there are other approaches that are slightly different which could also be used to solve this challenge. This is just one of the 3 approaches I took when I first solved this challenge.