class Pizza {
constructor(crust, toppings, howMany) {
this.crust = prompt('Choose your crust: ');
this.howMany = +prompt('How many toppings do you want?');
this.array = [];
}
makeTopping() {
for(let i = 1; i <= this.howMany; i++) {
this.toppings = prompt('Choose your topping: ');
this.array.push(this.toppings);
}
}
makePizza() {
console.log(`Your order is done! You choose ${this.crust} crust with these toppings: ${this.array.join(', ')}`);
}
}
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());
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());
this.toppings
на const toppings
array
осмысленное имя.console.log
в последней строке бессмысленнен. Либо возвращайте значение из функции, либо вызывайте ее просто так.параметры не используются, забыла убрать из конструктора)
const crust = prompt('Choose your crust: ');
const howMany = +prompt('How many toppings do you want?');
const personalPizza = new Pizza(crust, howMany);