Challenge: Let's Make a Burger
This challenge will test your skills in implementing mixins in JavaScript.
We'll cover the following
Problem statement #
In this challenge, you are given four classes:
-
Vegetables
-
Meat
-
Sauces
-
Burger
Your task is to combine these classes so that the methods of all three classes Vegetables
, Meat
, and Sauces
are available to a Burger
object instance. You also need to ensure that if a new class is added, its methods should also be available to Burger
class.
You have to do this by implementing the combineClasses
function.
Note: Write your implementation so that the code will work for any number of classes added. As mentioned earlier, the methods of any new class should be available to
Burger
.
Input #
Several classes
Output #
Burger object having access to all the methods of different classes
Sample input #
class Vegetables {
veggies() {
return "Choose Veggies"
}
}
class Meat {
meat() {
return "Choose Meat"
}
}
class Burger(){}
var burger = new Burger()
burger.veggies()
burger.meat()
Sample output #
"Choose Veggies"
"Choose Meat"
Level up your interview prep. Join Educative to access 70+ hands-on prep courses.