this.toppings
на const toppings
array
осмысленное имя.console.log
в последней строке бессмысленнен. Либо возвращайте значение из функции, либо вызывайте ее просто так.class Pizza {
constructor() {
this.crust = prompt('Choose your crust: ');
this.toppingsCount = +prompt('How many toppings do you want?') || 0;
this.toppings = [];
}
makeToppings() {
const {toppings, toppingsCount} = this;
for(let i = toppingsCount; i--;) {
toppings.push(prompt('Choose your topping: '));
}
}
makePizza() {
const {crust, toppings} = this;
return `Your order is done! You choose ${crust} crust with these toppings: ${toppings.length ? toppings.join(', ') : 'nothing'}`;
}
}
let personalPizza = new Pizza();
personalPizza.makeTopping();
console.log(personalPizza.makePizza());
class Pizza {
constructor() {
this.crust = prompt('Choose your crust: ');
this.array = new Array(+prompt('How many toppings do you want?')).fill(0);
}
makeTopping() {
this.array = this.array.map(function (t) { return prompt('Choose your topping: ') })
}
makePizza() {
return `Your order is done! You choose ${this.crust} crust with these toppings: ${this.array.join(', ')}`
}
}
let personalPizza = new Pizza();
personalPizza.makeTopping();
alert(personalPizza.makePizza());