Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function computerStore(arr) {
- let customerType = arr.pop();
- let prices = arr.map(x => Number(x));
- let priceWithoutTaxes = 0;
- let taxes = 0;
- let totalItemPrice = 0;
- let totalTaxes = 0;
- let totalPrice = 0;
- for (let i = 0; i < prices.length; i++) {
- let price = prices[i];
- if (price < 0) {
- console.log("Invalid price!");
- continue;
- }
- itemTaxes = price * 0.2;
- totalItemPrice = price + itemTaxes;
- totalTaxes += itemTaxes;
- priceWithoutTaxes += price;
- totalPrice += totalItemPrice;
- }
- if (customerType === "special") {
- totalPrice -= totalPrice * 0.1;
- }
- if (totalPrice === 0) {
- console.log("Invalid order!");
- } else {
- console.log("Congratulations you've just bought a new computer!");
- console.log(`Price without taxes: ${priceWithoutTaxes.toFixed(2)}$`)
- console.log(`Taxes: ${totalTaxes.toFixed(2)}$`);
- console.log(`-----------`);
- console.log(`Total price: ${totalPrice.toFixed(2)}$`);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment