Ivankooo1

Mobile operator

May 30th, 2019
197
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function calculateSumForService(input){
  2.     let contractLength = input.shift();
  3.     let mobilePlan = input.shift();
  4.     let mobileInternetIncluded = input.shift();
  5.     let paidMonths = Number(input.shift());
  6.     let monthlyFee = 0;
  7.     let totalSum = 0;
  8.  
  9.     if (contractLength === "one") {
  10.         switch (mobilePlan) {
  11.             case "Small": monthlyFee = 9.98; break;
  12.             case "Middle": monthlyFee = 18.99; break;
  13.             case "Large": monthlyFee = 25.98; break;
  14.             case "ExtraLarge": monthlyFee = 35.99;break;
  15.         }
  16.     }
  17.     else {
  18.         switch (mobilePlan) {
  19.             case "Small": monthlyFee = 8.58; break;
  20.             case "Middle": monthlyFee = 17.09; break;
  21.             case "Large": monthlyFee = 23.59; break;
  22.             case "ExtraLarge": monthlyFee = 31.79;break;
  23.         }
  24.     }
  25.  
  26.     if (mobileInternetIncluded ==="yes"){
  27.         if (monthlyFee <= 10) {
  28.             monthlyFee = (monthlyFee + 5.50) * paidMonths;
  29.             console.log(monthlyFee.toFixed(2) + " lv.");
  30.         }
  31.         else if (monthlyFee <= 30){
  32.             monthlyFee = (monthlyFee + 4.35) * paidMonths;
  33.             console.log(monthlyFee.toFixed(2) + " lv.");
  34.         } else {
  35.  
  36.             monthlyFee = (monthlyFee + 3.85) * paidMonths;
  37.             console.log(monthlyFee.toFixed(2) + " lv.");
  38.         }
  39.     }
  40.    
  41.     totalSum = monthlyFee * paidMonths;
  42.  
  43.    if (contractLength === "two") {
  44.         totalSum = 0.9625 * totalSum;
  45.         console.log(totalSum.toFixed(2) + " lv.");
  46.     }
  47.     }
  48.  
  49. calculateSumForService(['one','Small','yes',10]);
  50. calculateSumForService(['two','Large','no',10]);
Advertisement
Add Comment
Please, Sign In to add comment