Question: (Answer this question with thumb up - Using Javascript to write and js to run) Write a function, addColourPreference, which takes a user argument, an
(Answer this question with thumb up - Using Javascript to write and js to run)
Write a function, addColourPreference, which takes a user argument, an Object, and a colour string argument and returns the user Object with a new Colour Preference property. Your function should work like this:
let user = { name: "Yan" }; user = addColourPreference(user, 'red'); The user object should now how a Colour Preference property with the value red, that is, the user object would look like this:
{ name: Yan, Colour Preference: red}
Part 2 (3 Marks)
Similar to Part 1, write a function, removeColourPreference, which takes a user argument, an Object, and returns the user Object with a the Colour Preference property removed. Your function should work like this:
let user = { name: "Yan" }; // Add a Colour Preference of red user = addColourPreference(user, 'red'); // Remove Colour Preference from the user user = removeColourPreference(user); After calling your function, the user object should NOT have a Colour Preference property: { name: Yan }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
