r/javaScriptStudyGroup • u/Fancy-Feeling-2052 • Dec 14 '23
Need help with an exercise, please.
Hi, I'm learning JavaScript and this is one of the exercises that I can't get through, I was hopping someone could guide me a bit.
You see I'm leaning Objects, this is what I have to do:
Add a new property to the pirateProfile
called pirateName
and set this to the value of 'Blackbeard'Remove the realName
property.Change the value of piecesOf8
on the treasure
key to be 8 rather than 7.Change the shipName
property to its new value of Queen Anne's Revenge without changing the orinigal object.This is the code given:
function createPirate() {const pirateProfile = {
realName: 'Edward Teach',
shipName: 'La Concorde',
treasure: {
gems: 10,
piecesOf8: 7,
goldCoins: 150
}
};return pirateProfile;}
----
I literal tried to find how to mutate a function Object but without luck. And every time I write the way is taught like pirateProfile.pirateName = 'Blackbeard' it gives '✕ ReferenceError: pirateName is not defined '.
1
u/chunkysmunchies Dec 14 '23
Get your object outside the function