Make a Person -1

Tell us what’s happening:
I don’t get is it correct expected output
" bob.getFullName() should return “Haskell Curry” after bob.setLastName("Curry") ."
It is the only criteria in this task which i can’t pass and i don’t understand why getFullName should has first and last name changed if we set only last name

Your code so far


var Person = function(first,Last) {
  // Complete the method below and implement the others similarly
   
  this.getFullName = function() {
    return first + " " + Last;
  }
  this.getFirstName = function() {
    return first;
  }
  this.getLastName = function() {
    return Last;
  }
  this.setFirstName = function(input) {
   first = input;  
  }
  this.setLastName = function(input) {
    Last = input;
  }
  this.setFullName = function(input) {
    let lt = input.split(" ");
    first = lt[0];
    Last = lt[1];
  }
};

var bob = new Person('Bob','Ross');
bob.setLastName("Curry")
console.log(bob.getFullName());


Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.98 Safari/537.36.

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

They were a bit unclear, but the Person constructor doesn’t take two parameters, only one.
So when the tests are run the parameter will be a single string e.g. “Bob Ross” not “'Bob” and “Ross”.

It is not my case because getFullName() return changed name depends on which name i set

I changed my code on two parameters. Is not it allowed?

Ding ding ding! changing the function to take two parameters of first and last rather than one firstAndLast is essentially changing the rules of the game. And the validator is calling you out on “cheating”

1 Like

Thank you! I did it

var Person = function(firstAndLast) {
  // Complete the method below and implement the others similarly
   let lt = firstAndLast.split(" ");
  this.getFullName = function() {
    return lt[0] + " " + lt[1];
  }
  this.getFirstName = function() {
    return lt[0];
  }
  this.getLastName = function() {
    return lt[1];
  }
  this.setFirstName = function(input) {
    return lt[0] = input;
  }
  this.setLastName = function(input) {
   return lt[1] = input;
  }
  this.setFullName = function(input) {
    let rt = input.split(" ");
    lt[0] = rt[0];
    lt[1] = rt[1];
    
  }
};

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