Advertisement
Liliana797979

mobile operator1

Feb 18th, 2021
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function mobileOperator(input) {
  2.     let durationOfContract = input[0];
  3.     let typeOfContract = input[1];
  4.     let mobileInternet = input[2];
  5.     let monthsCount = Number(input[3]);
  6.     let price = 0;
  7.     let totalPrice = 0;
  8.  
  9.     switch (durationOfContract) {
  10.         case "one":
  11.             switch (typeOfContract) {
  12.                 case "Small":
  13.                     price = 9.98;
  14.                     break;
  15.                 case "Middle":
  16.                     price = 18.99;
  17.                     break;
  18.                 case "Large":
  19.                     price = 25.98;
  20.                 break;
  21.                 case "ExtraLarge":
  22.                     price = 35.99;
  23.                     break;
  24.             }
  25.             break;
  26.         case "two":
  27.             switch (typeOfContract) {
  28.                 case "Small":
  29.                     price = 8.58;
  30.                     break;
  31.                 case "Middle":
  32.                     price = 17.09;
  33.                     break;
  34.                 case "Large":
  35.                     price = 23.59;
  36.                 break;
  37.                 case "ExtraLarge":
  38.                     price = 31.79;
  39.                     break;
  40.             }
  41.             break;
  42.         }
  43.  
  44.     if (durationOfContract === "one" && mobileInternet === "yes" ) {
  45.         if (price <= 10) {
  46.             price = price + 5.50;
  47.         }
  48.         else if (price <= 30) {
  49.             price = price + 4.35;
  50.         }
  51.         else if (price > 30) {
  52.             price = price + 3.85;
  53.         }
  54.  
  55.         if (durationOfContract === "two" && mobileInternet === "yes") {
  56.             price = price - (price * 0.0375);
  57.         } else if (mobileInternet === "no") {
  58.             price = price;
  59.         }
  60.        
  61.         totalPrice = price * monthsCount;
  62.        
  63.         console.log(`${totalPrice.toFixed(2)} lv.`);
  64.     }
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement