Why do setter methods only take one parameter?

THIS excercise

const demoObject = {
firstName: ‘Alex’,
lastName: ‘Breeze’,

//LET'S CREATE A SETTER METHOD // WHAT IS A SETTER METHOD??? A SETTER METHOD IS A METHOD THAT REASSIGN INNER PROPERTIES OF AN OBJECT
set rename(newFirst, newLast) { //create set method rename
	if (typeof firstName === 'string' && typeof lastName === 'string') /*If statment checks for right data type*/ {
		if (typeof newFirst === 'string' && typeof newLast === 'string') { //if data type is right
			firstName: newFirst, //these values are reassigned
			lastName: newLast,	//these values are reassigned
		} else {
			console.log('The names must be strings.')//if data type of newFirst and/or newLast is wrong this prints
		}
	} else {
		return `First and/or last name of invalid type or not found`//if data type of firstName and/or lastName is wrong
	}
},	

}
//NOW LETS CALL OUR SETTER METHOD!!!
demoObject.rename(‘John’, ‘Cena’);

Setters only take one parameter because they are special methods that expect a value and set the property to that value, upon validation of type.

What your code is attempting to do is set multiple properties in one go. The code shouldn’t work, though since demoObject.rename is not a function. We cannot call a setter directly.

We could quite easily get a fullName…

person = {
    firstName: 'John',
    lastName: 'Doe',
    get fullName () {
        return [this.firstName, this.lastName].join(' ')
    }
}

console.log(person.fullName)
//  John Doe

Now let’s consider the above with the full compliment of getters and setters…

person = {
    _firstName: 'John',
    _lastName: 'Doe',
    get firstName () {
        return this._firstName
    },
    set firstName (name) {
        this._firstName = name
    },
    get lastName () {
        return this._lastName
    },
    set lastName (name) {
        this._lastName = name
    },
    get fullName () {
        return [this.firstName, this.lastName].join(' ')
    }
}