var items = ['0','1','2','3','4'];
items[0] = {name:'Отвертка',price:'150'};
items[1] = {name:'Ключ',price:'100'};
items[2] = {name:'Зубило',price:'180'};
items[3] = {name:'Напильник',price:'200'};
items[4] = {name:'Молоток',price:'500'};
console.log('Купите',items[4].name,'по цене',items[4].price,'руб.');
var x;
var discount;
function showDiscount(items, x) {
if (x < 10) {
discount = 5;
}
else if (10 < x < 50) {
discount = 7;
}
else if (50 < x < 100) {
discount = 10;
}
else if (x > 100) {
discount = 15;
}
var result = x*(prices-0.01*prices*discount);
var benefit = x*0.01*prices*discount;
console.log(items.name,'- стоимость партии из',x,'штук',items.price,'руб. (скидка',discount,'%), ваша выгода',benefit,'руб.');
}
showDiscount([0],150);
const items = [
{name:'Отвертка',price:'150', quantity: 100},
{name:'Ключ',price:'100', quantity: 200},
{name:'Зубило',price:'180', quantity: 500},
{name:'Напильник',price:'200', quantity: 1000},
{name:'Молоток',price:'500', quantity: 250}
];
function getDiscount(x) {
if(x < 10) return 5;
if(x > 10 && x < 50) return 7;
if(x > 50 && x < 100) return 10;
if(x > 100) return 15;
}
function getCustomerBenefit(item) {
const benefit = item.quantity * 0.01 * item.price * getDiscount(item.quantity);
console.log('money you can save due to discount', benefit);
return benefit;
}
function calculateTotalPayment(item) {
const beforeDiscount = item.quantity * item.price;
const totalPayment = beforeDiscount - getCustomerBenefit(item);
console.log('beforeDiscount', beforeDiscount);
console.log('total payment(discount included)', totalPayment);
return totalPayment;
}
calculateTotalPayment(items[4]);