Can anyone suggest whats wrong in the code?

getFullName is still set to the one applied earliest even after setting it afterwards.
I am new to JS, can anyone please suggest what am I doing wrong?

var Person = function(firstAndLast) {
 let fullName  = firstAndLast;
 this.getFirstName = () => fullName.split(' ')[0];
 this.getLastName = () => fullName.split(' ')[1];
 this.getFullName = () => fullName;
 this.setFirstName = first =>  fullName = first + " " + fullName.split(" ")[1];
 this.setLastName = last =>  fullName = fullName.split(" ")[0] + " " + last ;
 this.setFullName = firstAndLast => firstAndLast; 

var bob = new Person('Bob Ross');
bob.setFullName("Haskell Curry")

Can you post a link to the challenge please?

I’ve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.

You can also use the “preformatted text” tool in the editor (</>) to add backticks around text.

See this post to find the backtick on your keyboard.
Note: Backticks (`) are not single quotes (’).

I think this isn’t setting fullName

1 Like

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