Intermediate Algorithm Scripting - Make a Person

Tell us what’s happening:
Describe your issue in detail here.

Only the tests for “undefined” and “instanceof” are passing, none of the other tests are passing, and I’m not sure why. I have console.logged each function to figure out if they would give me what I asked for, and they did, but when I run the entire parent function, it does not pass any of the tests that require name-based answers…

Your code so far

const Person = function(firstAndLast) {
  // Only change code below this line
  function getFirstName(str) {
    let strArr = str.split(" ");
    return strArr[0];
  }


  function getLastName(str) {
    let strArr = str.split(" ");
    return strArr[1];
  }


  function getFullName(str) {
    let strArr = str.split(" ");
    return strArr.join(" ");
  }

  
  function setFirstName(first) {
    return first;
  }
  

  function setLastName(last) {
    return last;
  }

  function setFullName(firstAndLast) {
    let strArr = firstAndLast.split(" ");
    let first = strArr[0];
    let last = strArr[1];
    return first + " " + last;
  }


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

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

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/113.0

Challenge: Intermediate Algorithm Scripting - Make a Person

Link to the challenge:

Oh, so I can create the functions in the same way and then return them at the top? Kind of like:

return 

this.getFirstName = function( ) {

}

this.getLastName = function( ) {

}

// ...etc

Kind of like returning a list of functions set to the “this” keyword??

Tell us what’s happening:
Describe your issue in detail here.

Okay, I have re-worked my code, and more of the tests are passing, but about half of them are not. Somehow, the “Object.keys” test is no longer passing…not sure why that is. Also, all the “Haskell Curry” tests are not passing, when they were at first. So the passing tests have kind of flipped from my last code.

Your code so far

const Person = function(firstAndLast) {
  // Only change code below this line

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


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


  this.getFullName = function () {
    let fullName = firstAndLast;
    return fullName
  };

  
  this.setFirstName = function (name) {
    let fullName = firstAndLast;
    fullNameArr = fullName.split(" ");
    fullName = name + " " + fullNameArr[1];
  };
  

  this.setLastName = function (name) {
    let fullName = firstAndLast;
    fullNameArr = fullName.split(" ");
    fullName = fullNameArr[0] + " " + name;
  };

  this.setFullName = function (name) {
    // let fullName = firstAndLast;
    fullName = name;
  };



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

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

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/113.0

Challenge: Intermediate Algorithm Scripting - Make a Person

Link to the challenge:

This all is an issue. You defined this method twice, and the second one isn’t going to work. Also, I don’t think you want to use return inside of the constructor?

These three should be modifying the variable firstAndLast like how these use it:

The variable firstAndLast is sorta a ‘hidden’ variable that holds the parts of the name but isn’t accessible except via the 6 methods you defined.

ohhhh…I think I get it. It’s more of rearranging the code of the “get” functions to result in a reassignment…I’ll see what I can change to try and make it work. Thanks!

Okay, this is passing most of the tests, but some of them aren’t passing. Namely:

// not passing 
bob.getFirstName() should return the string Bob.

// not passing
bob.getLastName() should return the string Ross.

// not passing
bob.getFullName() should return the string Bob Ross.

// not passing
bob.getFullName() should return the string Haskell Ross after bob.setFirstName("Haskell").

This is the current code and it should be passing…I checked several times for spelling and syntax errors, so I don’t think there are. But I finally kind of understood what was supposed to be happening here, so I have no idea why it’s not passing.

const Person = function(firstAndLast) {
  // Only change code below this line

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


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

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

  
  this.setFirstName = function (first) {
    firstAndLast = first + " " + firstAndLast.split(" ")[1];
  };
  

  this.setLastName = function (last) {
    firstAndLast = firstAndLast.split(" ")[0] + " " + last;
  };

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

  // Complete the method below and implement the others similarly

};

Ooohhhh, shame on us! Your code works if you put back

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

at the bottom. We should be creating any variables we need for the tests, but we aren’t and its giving this false failures for you!

I never moved it lol, this is the whole code without all my console logs at the end:

const Person = function(firstAndLast) {
  // Only change code below this line

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


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

  
  this.setFirstName = function (first) {
    firstAndLast = first + " " + firstAndLast.split(" ")[1];
  };
  

  this.setLastName = function (last) {
    firstAndLast = firstAndLast.split(" ")[0] + " " + last;
  };

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

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

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

But just to be sure, I cut the code, pasted it back and those 4 tests still aren’t passing…not sure what’s happening here.

Hmm, that all is passing for me

I also put the “getFullName” statement back at the bottom where it was initially, and that obviously made no change, not that I was really expecting it to. Should I reset the lesson and try pasting it back into it after it refreshes??

I’d try clearing your cache, logging back in, and then pasting all this in.

Okay, I’ll try that. Thanks. I’ll notify if there are any changes or if it passes or whatnot after I try it. :grin:

1 Like

It worked, I had to reset the lesson and paste it back in. Thanks!!!

1 Like

Issue created here:

1 Like

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.