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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started