Advertisement
Spocoman

01. Computer Store

Nov 4th, 2023
1,013
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function computerStore(input) {
  2.     let totalPrice = 0, price;
  3.  
  4.     let command = input.shift();
  5.  
  6.     while (command != "special" && command != "regular") {
  7.         price = Number(command);
  8.         if (price > 0) {
  9.             totalPrice += price;
  10.         } else {
  11.             console.log("Invalid price!")
  12.         }
  13.         command = input.shift();
  14.     }
  15.  
  16.     if (totalPrice == 0) {
  17.         console.log("Invalid order!");
  18.     } else {
  19.         console.log("Congratulations you've just bought a new computer!");
  20.         console.log(`Price without taxes: ${totalPrice.toFixed(2)}$`);
  21.         console.log(`Taxes: ${(totalPrice / 5).toFixed(2)}$`);
  22.         console.log("-".repeat(11));
  23.         console.log(`Total price: ${(totalPrice * 1.2 * (command === "special" ? 0.9 : 1)).toFixed(2)}$`);
  24.     }
  25.     return;
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement