Liliana797979

computer store - fundamentals

Jun 17th, 2021
175
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function computerStore(arr) {
  2.     let price = 0;
  3.     let customer = "";
  4.     for (const line of arr) {
  5.        
  6.         if (line == "special" || line == "regular") {
  7.             customer = line;
  8.         break;
  9.         }
  10.         let currentPrice = Number(line);
  11.         if (currentPrice <= 0) {
  12.             console.log(`Invalid price!`);
  13.             continue;
  14.         }
  15.         price += currentPrice;
  16.     }
  17.     if (price = 0) {
  18.         console.log(`Invalid order!`);
  19.     } else {
  20.         let tax = price * 0.2;
  21.         let total = price + tax;
  22.         if (customer == `special`) {
  23.             total *= 0.9;
  24.     }
  25.     console.log(`Congratulations you\'ve just bought a new computer!
  26. Price without taxes: ${price.toFixed(2)}$
  27. Taxes: ${tax.toFixed(2)}$
  28. -----------
  29. Total price: ${total.toFixed(2)}$`);
  30.  
  31.    }
  32. }
Advertisement
Add Comment
Please, Sign In to add comment