I am trying to construct the addTopping method such that it can take in multiple toppings to push into the toppings array instead of one. I'm not sure how to tackle this. I've seen some of the other posts using .push.apply() which doesn't work in my case since that creates an object.
class Pizza {
constructor(size, crust, stuffedcrust) {
this.size = size;
this.crust = crust;
this.stuffedcrust = stuffedcrust;
this.toppings = ["Cheese"];
}
addTopping(topping) {
this.toppings.push(topping);
}
removeTopping(topping) {
let index = this.toppings.indexOf(topping);
this.toppings.splice(index, 1);
}
}
let pizza1 = new Pizza("Medium", "thin", true);
pizza1.addTopping("Pepperoni", "Green Peppers", "Mushrooms");
console.log(pizza1);
pizza1.addTopping will only add the first item as of now.