Рассчитать цену с учётом скидки
Надо рассчитать цену с учётом скидки, у меня пишет ошибку, что надо исправить?
const price = {
price: 10,
discount: 0.15,
getPrice: function () {
return this.price;
},
getPriceWithDiscount: function () {
return getPrice - (this.discount / this.price);
}
}
|
const price = {
price: 10,
discount: 0.15,
getPrice: function () {
return this.price;
},
getPriceWithDiscount: function () {
return this.price- (this.discount / this.price);
}
}
|
мб так?
getPriceWithDiscount: function () {
return this.price - (this.discount / this.price);
}
|
const price = {
price: 10,
discount: 0.15,
getPrice: function () {
return this.price;
},
getPriceWithDiscount: function () {
return this.getPrice() - (this.discount / this.price);
}
}
alert(price.getPriceWithDiscount());
j0hnik прав в том плане, что getPrice - лишнее действие, о чем говорит и this.price в этом же выражении. PS:только мне кажется, что скидка не так вычисляется |
Dilettante_Pro,
да не так, * вместо /! return this.getPrice() - (this.discount * this.price); если 0.15 это скидка в 15% |
Цитата:
|
| Часовой пояс GMT +3, время: 10:29. |