Pijomir

Computer Store

Oct 11th, 2023 (edited)
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function printReceiptForComputer(input) {
  2.     let priceWithoutTaxes = 0;
  3.     let taxes = 0;
  4.     let priceWithTaxes = 0;
  5.     let typeOfClient = input.pop();
  6.     while (input.length > 0) {
  7.         let currentPrice = Number(input.shift());
  8.         if (currentPrice <= 0) {
  9.             console.log('Invalid price!');
  10.         } else {
  11.             priceWithoutTaxes += currentPrice;
  12.             taxes += currentPrice * 0.2;
  13.             priceWithTaxes += currentPrice * 1.2;
  14.         }
  15.     }
  16.  
  17.     if (priceWithTaxes === 0) {
  18.         console.log('Invalid order!');
  19.     } else {
  20.         console.log('Congratulations you\'ve just bought a new computer!');
  21.         console.log(`Price without taxes: ${priceWithoutTaxes.toFixed(2)}$`);
  22.         console.log(`Taxes: ${taxes.toFixed(2)}$`);
  23.         console.log(`${'-'.repeat(11)}`);
  24.         console.log(`Total price: ${typeOfClient === 'regular' ? priceWithTaxes.toFixed(2) : (priceWithTaxes * 0.9).toFixed(2)}$`);
  25.        
  26.     }
  27. }
Add Comment
Please, Sign In to add comment