@hfe.as008 You are calling the method which is using the caller method in the method. It make errors. I would say, set the value fullName in the main scope. And you can use .split(" ")[number] instead of using inline if statements. In getFirstName and getLastName function you can use the syntax that I showed you in upper.
These requirements mean that you cannot create this.firstName or this.lastName variables. You can create variables that are scoped inside of the Person object but are not bound to this., and that’s what I would do.
for this challenge, I used the principle of ‘closure’ and ‘getter’/‘setter’ functions; using ‘getter function’ secures the original value of the variables; using ‘setter function’ allows user to change value of variables to new ones; however, these functionalities are made available only to instances of the constructor and not to public.
split the '(firstAndLast) '; in that way, you’d be able to set up the variables for the ‘firstName’ and ‘lastName’
Okay, i understand what you talking about.
It’s funny, how FCC answer checker accepts my answer =)
I tried to make these variables inside the scope of the Person object, but i dont understand how to use them inside methods. When I call method, it doesn’t overwrite values of these variables.
var Person = function(firstAndLast) {
// Only change code below this line
let name = firstAndLast;
this.printInput = function() {
console.log(name);
};
};
let bob = new Person('Bob Ross');
bob.printInput();