Make a Person - can't pass a bunch of test

Make a Person - can't pass a bunch of test
0.0 0

#1

Tell us what’s happening:
Hey everyone, so I’m trying to solve this challenge but Ive been staring at the screen for a couple hours and I’m really at my wits end. Can someone please nudge me in the right direction?
Thanks so much.

Your code so far


function Person(firstAndLast) {
  // Complete the method below and implement the others similarly
  let fullName = firstAndLast;
  let splitNames = fullName.split(" ");
  let first = splitNames[0];
  let last = splitNames[1]; 

  //Setters:
  this.setFirstName = function(first) {
    this.firstName = first;
  };
   this.setLastName = function(last) {
    this.lastName = last;
  };
  this.setFullName = function(fullName) {
    this.fullName = fullName;
  };

  //Getters:
  this.getFirstName = function() { 
            return this.firstName;
        }; 
  this.getLastName = function() { 
            return this.lastName;
        }; 
  this.getFullName = function() { 
            return this.fullName;
        };   
}


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

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.87 Safari/537.36.

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


#2

I will nudge you just a little.

The first test you do not pass is bob.getFirstName(). It should return “Bob”. You need to figure out what it is returning instead. Your code for the getFirstName method is the following:

  return this.firstName;

So you know what you are returning, put the following console.log statement on the line before this return and look at your browser’s console (Ctrl + Shft + J in Chrome) and then see if you can figure out why it is not “Bob”.

console.log('The getfirstName method is going to return ' + this.firstName);

#3

I’m guessing it’s because I’m not setting the props in the constructor.
But if I do then none of the setters work and Object.keys(bob).length is 9.


#4

You have a local variable named first which contains the firstName that was originally passed into the function. Think about how you could use this variable.