Make a person - Object

Dear Coding Community!

I couldn’t solve the task the way it was intended to be solved.
I tried to rely on a previous task on how to write getters and setters.
From my beginner’s perspective, my code does almost the same as the one that should have been used in the task “Make a person”. Leaving the question aside whether my code fully works (that would be interesting too…) …

From an experienced coder’s perspective, what are the main differences/(dis-)advantages of doing it either way?


class Person {
constructor(firstAndLast) {
  this.firstAndLast = firstAndLast;
}

get fullName() {
  console.log(this.firstAndLast);
  return this.firstAndLast;
}

set fullName(newFullName) {
  this.firstAndLast = newFullName;
  
}

get firstName() {
    console.log(this.firstAndLast.split(/\s/)[0])
    return this.firstAndLast.split(/\s/)[0];
}

set firstName(newFirstName){
    this.firstAndLast = this.firstAndLast.replace(/\w+(?=\s)/,newFirstName);
}


get lastName() {
    console.log(this.firstAndLast.split(/\s/)[1])
    return this.firstAndLast.split(/\s/)[1];
}

set lastName(newLastName){
    this.firstAndLast = this.firstAndLast.replace(/(?<=\s)\w+/,newLastName)
}
}

const bob = new Person('Bob Ross');
bob.firstName;
bob.lastName;
bob.fullName;
bob.firstName = "Peter"
bob.firstName
bob.lastName = "O'Toole"
bob.lastName
bob.fullName


  **Your browser information:**

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

Challenge: Make a Person

Link to the challenge:

Nice Job! this code looks complicated