educative.io

Educative

Running into issues while returning an object in function. Need help

Question: Modify this function to take in an object as a parameter. The object will represent a person and have a firstName property and a lastName property. Return the person’s full name, separated by a space.

My solution:

function getFullName(name1, name2) {
    var person = {
        firstName: name1,
        lastName: name2
    };
    return `${person.firstName} ${person.lastName}`;
}

Chrome console output:
// passing my full name with this >> getFullName(‘Souvik’, ‘Kundu’);

// output >> ‘Souvik Kundu’

I’m getting the desired output but it does not pass the test in this course. Kindly help.

The function just takes in an object. So anything like x works. Then you know that it has firstName and lastName as its properties. You just do x.firstName + " " + x.lastName to get the answer.