Advertisement
igrilkul

Untitled

Jun 26th, 2018
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. let aha =(function () {
  2.  
  3.     let protein = 0;
  4.     let carbohydrates = 0;
  5.     let fat = 0;
  6.     let flavours = 0;
  7.  
  8.     function instructions(input) {
  9.         if(input!=="report")
  10.         {
  11.            let [command,item,quantity] = input.split(" ");
  12.             if(command==="restock")
  13.             {
  14.                 switch (item)
  15.                 {
  16.                     case "protein":
  17.                     {
  18.                         protein+=Number(quantity);
  19.                         break;
  20.                     }
  21.  
  22.                     case "carbohydrates":
  23.                     {
  24.                         carbohydrates+=Number(quantity);
  25.                         break;
  26.                     }
  27.  
  28.                     case "fat":
  29.                     {
  30.                         fat+=Number(quantity);
  31.                         break;
  32.                     }
  33.  
  34.                     case "flavours":
  35.                     {
  36.                         flavours+=Number(quantity);
  37.                         break;
  38.                     }
  39.                 }
  40.             }
  41.             else if(command==="prepare")
  42.             {
  43.                 switch (item)
  44.                 {
  45.                     case "Apple":
  46.                     {
  47.                         if(carbohydrates>=quantity*1 && flavours>=quantity*2)
  48.                         {
  49.                             carbohydrates-=quantity*1;
  50.                             flavours-=quantity*2;
  51.                             console.log("Success");
  52.                         }
  53.                         else console.log("error");
  54.                         break;
  55.                     }
  56.  
  57.                     case "Coke":
  58.                     {
  59.                         if(carbohydrates>=quantity*10 && flavours>=quantity*20)
  60.                         {
  61.                             carbohydrates-=quantity*10;
  62.                             flavours-=quantity*20;
  63.                             console.log("Success");
  64.                         }
  65.                         else console.log("error");
  66.                         break;
  67.                     }
  68.  
  69.                     case "Burger":
  70.                     {
  71.                         if(carbohydrates>=5*quantity && fat>=quantity*7 && flavours>=quantity*3)
  72.                         {
  73.                             carbohydrates-=5*quantity;
  74.                             fat-=quantity*7;
  75.                             flavours-=quantity*3;
  76.                             console.log("Success");
  77.                         }
  78.                         else console.log("error");
  79.                         break;
  80.                     }
  81.  
  82.                     case "Omelet":
  83.                     {
  84.                         if(protein>=quantity*5 && fat>=quantity*1 && flavours>=quantity*1)
  85.                         {
  86.                             protein-=quantity*5;
  87.                             fat-=quantity*1;
  88.                             flavours-=quantity*1;
  89.                             console.log("Success");
  90.                         }
  91.                         else console.log("error");
  92.                         break;
  93.                     }
  94.  
  95.                     case "Cheverme":
  96.                     {
  97.                         if(protein>=quantity*10 && carbohydrates>=quantity*10 && fat>=quantity*10 && flavours>=quantity*10)
  98.                         {
  99.                             protein-=quantity*10;
  100.                             carbohydrates-=quantity*10;
  101.                             fat-=quantity*10;
  102.                             flavours-=quantity*10;
  103.                             console.log("Success");
  104.                         }
  105.                         else console.log("error");
  106.                         break;
  107.                     }
  108.                 }
  109.             }
  110.         }
  111.         else
  112.         {
  113.             console.log(`protein=${protein} carbohydrate=${carbohydrates} fat=${fat} flavour=${flavours}`);
  114.         }
  115.     }
  116.  
  117.     return instructions;
  118. })();
  119.  
  120. console.log(aha("restock fat 5"));
  121. console.log(aha("restock carbohydrates 3"));
  122. console.log(aha("restock flavours 20"));
  123. console.log(aha("restock fat 5"));
  124. console.log(aha("prepare Apple 1"));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement