Advertisement
dimoBs

computer storage

Feb 23rd, 2021
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //01. Computer Store
  2. function solve(arr) {
  3.  
  4.     let taxes = 0.20;
  5.     let taxesSum = 0;
  6.     let flag = false;
  7.     let special = 0.90;
  8.     let priceSpecial = 0;
  9.     let prices = 0;
  10.  
  11.     arr.forEach(x => {
  12.         if (Number(x) && Number(x) > 0) {
  13.             prices += Number(x);
  14.  
  15.         } else if (Number(x) < 0) {
  16.             console.log(`Invalid price!`);
  17.  
  18.         } else if (x === 'special') {
  19.             flag = true;
  20.             taxesSum = (prices * taxes);
  21.             priceSpecial = (prices + taxesSum) * (1 - 0.10);
  22.  
  23.         } else if (x === 'regular' && prices > 0) {
  24.             flag = true;
  25.             taxesSum = (prices * taxes);
  26.             priceSpecial = (prices + taxesSum);
  27.         }
  28.     });
  29.  
  30.     if (flag) {
  31.         console.log(`Congratulations you've just bought a new computer!`)
  32.        console.log(`Price without taxes: ${prices.toFixed(2)}$`);
  33.        console.log(`Taxes: ${taxesSum.toFixed(2)}$`);
  34.        console.log(`-----------`);
  35.        console.log(`Total price: ${priceSpecial.toFixed(2)}$`);
  36.    } else {
  37.        console.log(`Invalid order!`);
  38.    }
  39. }
  40. // solve([1023,15,-20,-5.50,450,20,17.66,19.30,'regular'])
  41. solve(['regular']);
  42. // solve(['1050','200','450','2','18.50','16.86','special']);
  43. // solve(['1023','15','-20','-5.50','450','20','17.66','19.30', 'regular'])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement