ErolKZ

Untitled

Jun 6th, 2021
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.46 KB | None | 0 0
  1. function solve(input) {
  2.  
  3. let sum = 0;
  4. let sum2 = 0;
  5. let sum3 = 0;
  6.  
  7. let input0 = Number(input[0]);
  8. let input1 = Number(input[1]);
  9. let input2 = Number(input[2]);
  10. let input3 = Number(input[3]);
  11.  
  12.  
  13.  
  14. // Kilograms
  15. // sum is the price for a given kilograms
  16.  
  17. if (input1 < 10) {
  18.  
  19. sum = input0 * (20 / 100); // This is the price up to 10kg.
  20.  
  21. } else if (10 < input1 && input1 <= 20) {
  22.  
  23. sum = input0 * (50 / 100); // This is the price between 10 and 20kg.
  24.  
  25. } else if (input1 > 20) { // This is the price for above 20kg.
  26.  
  27. sum = input0;
  28.  
  29. }
  30.  
  31. // Days
  32. // sum2 is the price increase given the days
  33.  
  34. if (input2 > 30 ) {
  35.  
  36. sum2 = sum * (10 / 100); // The price beyond 30 days.
  37.  
  38. } else if (7 <= input2 && input2 <= 30) {
  39.  
  40. sum2 = sum * (15 / 100); // The price between 7 and 30 days.
  41.  
  42. } else if (input2 < 7) {
  43.  
  44. sum2 = sum * (40 / 100); // The price below 7 days.
  45.  
  46. }
  47.  
  48. // sum3 is the result of the price for given kilograms and the the additional price for the given days
  49.  
  50. sum3 = Number(sum) + Number(sum2);
  51.  
  52. // total is the multiplication of the total sum that has to be paid for one baggage and the baggages that are stored
  53.  
  54. let total = sum3 * input3;
  55.  
  56.  
  57.  
  58.  
  59. console.log('The total price of bags is: ' + total.toFixed(2) + ' lv.')
  60. }
  61.  
  62.  
Advertisement
Add Comment
Please, Sign In to add comment