Intermediate Algorithm Scripting - Make a Person

Tell us what’s happening:
Describe your issue in detail here.
My outputs match the outputs required by the tests, yet some of the tests are failing.

Your code so far

const Person = function(firstAndLast) {
  // Only change code below this line
  // Complete the method below and implement the others similarly
  let fullName = firstAndLast;
  this.getFullName = function() {
    return fullName;
  };

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

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

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

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

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

  return firstAndLast;
};

const bob = new Person('Bob Ross');
//console.log(bob);
console.log(bob.getFirstName());
console.log(bob.getLastName());
console.log(bob.getFullName());
bob.setFirstName("Haskell");
console.log(bob.getFullName());
bob.setLastName("Curry");
console.log(bob.getFullName());
bob.setFullName("Haskell Curry");
console.log(bob.getFullName());
console.log(bob.getFirstName());
console.log(bob.getLastName());
console.log(bob.fullName);

results of above logs to console:

Bob
Ross
Bob Ross
Haskell Ross
Haskell Curry
Haskell Curry
Haskell
Curry
undefined
undefined
6
true

Your browser information:

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

Challenge: Intermediate Algorithm Scripting - Make a Person

Link to the challenge:

when I copy and paste your functions only (without the extra logs and calls to the set function), the test passes.
try that.

2 Likes

That worked! Thank you !

1 Like

In case you wanted to know why that worked,
your original code ended after setting the first and last name to “Haskell curry” so the first test it ran
bob.getFirstName() returned “Haskell”.
instead of deleting it you could have also added a line:
bob.setFullName(“Bob Ross”) and it would also pass.

2 Likes

That makes sense! Thanks for taking the time to help and explain. I appreciate that very much.

Thank you so much!
I had the same problem and thanks to you I passed.
I always use log to check the output down there and never had had problem.

you have to be careful with variable scope. Glad you got it working.

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