Nested object

Call your two functions with the spaceship object in the code editor, then console.log() the spaceship object to confirm those properties were changed/added.

For this particular task I thought

is the right invoking but when I did as on the screen it got me right but still I could not understand why-----please explain thank you.

spaceship.greenEnergy() means invoke the method greenEnergy on the spaceship object which doesn’t exist in this case.

With greenEnergy(spaceship) this is a regular function which takes an object as an argument

You would use spaceship.greenEnergy() if greenEnergy() was a method that was included inside of the object spaceship. However in this case, greenEnergy() is just a regular function that takes an object as an input, therefore you use it as a regular function and use spaceship inside of the brackets.

thank you so much. I think i got it.

thank you for the clearing out. I got this now.

1 Like