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

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]; 

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

  this.getFirstName = function() { 
            return this.firstName;
  this.getLastName = function() { 
            return this.lastName;
  this.getFullName = function() { 
            return this.fullName;

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

Link to the challenge:

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);
1 Like

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.

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.