Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function computerStore(arr) {
- let price = 0;
- let customer = "";
- for (const line of arr) {
- if (line == "special" || line == "regular") {
- customer = line;
- break;
- }
- let currentPrice = Number(line);
- if (currentPrice <= 0) {
- console.log(`Invalid price!`);
- continue;
- }
- price += currentPrice;
- }
- if (price = 0) {
- console.log(`Invalid order!`);
- } else {
- let tax = price * 0.2;
- let total = price + tax;
- if (customer == `special`) {
- total *= 0.9;
- }
- console.log(`Congratulations you\'ve just bought a new computer!
- Price without taxes: ${price.toFixed(2)}$
- Taxes: ${tax.toFixed(2)}$
- -----------
- Total price: ${total.toFixed(2)}$`);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment