Need Help with an assertion error in a functions exercise

Hi. I am having trouble with an exercise dealing with functions. Here are the instructions:

  1. Declare a variable called myObject , and assign it the value of an object
  2. Declare a function called addKeys
  3. This function should take one parameter called object
  4. This function will add two keys named firstName and lastName to the given parameter
  5. The firstName key will be your first name as a string
  6. The lastName key will be your last name as a string
  7. This function will return the parameter
  8. Call the addKeys function outside its function definition and pass myObject as an argument.

This is what I did.
var myObject = {};

function addKeys(object) {

myObject = {‘firstName’: “Bill”, ‘lastName’: “Withers”};

return object;

}

addKeys(myObject);

However, I received an assertion error saying: should work with any object

AssertionError: expected {} to have keys ‘firstName’, and ‘lastName’

expect(addKeys(diffObj)).to.have.keys([‘firstName’, ‘lastName’]);
expect(myObject).to.be.empty;

What should I do to resolve this?

Hello @board8807139395, welcome to the forums! Is your error one generated by CC? In your code, inside your function, you act upon myObject, when the parameter is actually object. Therefore, you’re not doing anything to the parameter. You finally return object, but you haven’t done anything to that object. Since you pass in an empty object, you get an empty object returned.
I hope this helps!

1 Like

Thanks for the help. I believe I have it now.
var myObject = {};

function addKeys(object) {
object.firstName = “Bill”;
object.lastName = “Withers”;

return object;
}
addKeys(myObject);

1 Like