Make a Person making me crazy

Tell us what’s happening:
Gone back and forth on this so many times I can’t figure out why it isn’t being accepted.
All my test runs match the expected output in the tests but no dice.

Your code so far

// Fill in the object constructor with the following methods below:
// getFirstName()
// getLastName()
// getFullName()
// setFirstName(first)
// setLastName(last)
// setFullName(firstAndLast)
// Run the tests to see the expected output for each method. 
// The methods that take an argument must accept only one argument 
// and it has to be a string. These methods must be the only available 
// means of interacting with the object.

var Person = function(firstAndLast) {
  // Complete the method below and implement the others similarlyN
const name = firstAndLast.split(' ');
let firstName = name[0];
let lastName = name[1];
this.getFirstName = function() {
  return firstName;
this.getLastName = function() {
  return lastName;
this.getFullName = function() {
  return firstName + " " + lastName;  
this.setFirstName = function(fName) {
  firstName = fName;

this.setLastName = function(lName) {
  lastName = lName;

this.setFullName = function(fulName) {
  firstAndLast = fulName;

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

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.138 Safari/537.36.

Challenge: Make a Person

Link to the challenge:

If I’m not mistaken, you are missing the this. on the internal object variables.

Like these?

this.setFullName = function(fulName)

You have let firstName when I think you want this.firstName and such.

no, those should not be object properties as you need 6 properties on the object and those are all the methods

setFullName is wrong.

Yeah, you’re right. My mistake, I missread that part.

I think you need to remove all the set methods calls you have, as the tests are testing the bob object created in the challenge
edit: and as @kerafyrm say you have setFullName not doing what you want (you are not updating variables firstName and lastName)

@JeremyLT: do you want to create an issue on github for this? it seems an unnecessary headache

look at his setFullName function.

he has firstAndLast

Are you referring to removing the console.log statements where I am testing?

Is this how private variables are managed for an object? Huh.

I agree that we should tweak the test or add a // Don't change code below... .

@opalko, I was wrong at first. Ignore that.

You have two problems, as far as I can tell.

  1. Your private variables are only firstName and lastName in the way you’ve set this up. You need to update setFullName to only use those variables.
  2. You probably shouldn’t change the Bob object after it’s created when you submit the code.

the tests are checking what bob.getFirstName() returns, but you have changed the first name with the use of bob.setFirstName() so the test fail

this.setFullName = function(fulName){
   [ firstName, lastName ] = fulName.split(' ');

It’s great that you know how to do this, but we prefer to help users develop their own code rather than giving them solutions. Thanks for understanding.

Ok I am really lost now. Github? Great I know how to do this?..

I had the impression the moderators were about to submit a bug in the problem when there was none.

Using this is not required. Those variables become “private” properties of that object by virtue of them in the object’s scope.

OK. Ignore the thread so for @opalko .

You have in your setFullName a reference to a variable that does not exist. firstAndLast isn’t in your object, as you have set it up. You should instead use the same logic as your constructor and use the two variables you have, firstName and lastName.

Please let me know if I can be clearer.

After than, you’ll want to remove all of the code after var bob = new Person("Bob Ross") ;

1 Like

Your problem was very simple. You did almost everything correctly.

you had a method called: setFullName but it didn’t really set it.

Notice how your other set methods set the firstName variable and lastName variable correctly.

When setting the fullName you need to reassign the firstName and lastName values individually.

1 Like

if everything is fine but I add
bob.setFirstName("Cindy") the following test fail:

bob.getFirstName() should return "Bob".

Which is what’s happening for most of the not passing tests in case of OP code

1 Like

So I can repeat the first few lines and it works

this.setFullName = function(fulName) {
    firstAndLast = fulName.split(" ");
    firstName = firstAndLast[0];
    lastName = firstAndLast[1];
    firstAndLast = firstName + " " + lastName;
1 Like