I have this simple block of code written with OOP. I want to manipulate this sentence so that the last parameter (faveColor
), is changed to the actual colour specified. I know I need to write some sort of function to do this but I can't work out how.
I am really confused as to how to go about this in the cleanest possible way. Basically so that the sentence outputs 'Hello, my name is John Doe and my favourite colour is ${red/orange/blue/green} etc. with the color changing for each choice.
function Person(fullName, faveColour) {
this.name = fullName;
this.favouriteColour = faveColour;
this.greet = function () {
return `Hello, my name is ${this.name} and my favourite colour is ${this.favouriteColour}`;
};
}
const john = new Person('John Doe', 'red');
john.greet();
const jane = new Person('Jane Doe', 'orange');
jane.greet();
const red = '#ff0000';
const orange = '#ffa500';