Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //01. Computer Store
- function solve(arr) {
- let taxes = 0.20;
- let taxesSum = 0;
- let flag = false;
- let special = 0.90;
- let priceSpecial = 0;
- let prices = 0;
- arr.forEach(x => {
- if (Number(x) && Number(x) > 0) {
- prices += Number(x);
- } else if (Number(x) < 0) {
- console.log(`Invalid price!`);
- } else if (x === 'special') {
- flag = true;
- taxesSum = (prices * taxes);
- priceSpecial = (prices + taxesSum) * (1 - 0.10);
- } else if (x === 'regular' && prices > 0) {
- flag = true;
- taxesSum = (prices * taxes);
- priceSpecial = (prices + taxesSum);
- }
- });
- if (flag) {
- console.log(`Congratulations you've just bought a new computer!`)
- console.log(`Price without taxes: ${prices.toFixed(2)}$`);
- console.log(`Taxes: ${taxesSum.toFixed(2)}$`);
- console.log(`-----------`);
- console.log(`Total price: ${priceSpecial.toFixed(2)}$`);
- } else {
- console.log(`Invalid order!`);
- }
- }
- // solve([1023,15,-20,-5.50,450,20,17.66,19.30,'regular'])
- solve(['regular']);
- // solve(['1050','200','450','2','18.50','16.86','special']);
- // solve(['1023','15','-20','-5.50','450','20','17.66','19.30', 'regular'])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement