DraconiusNX

Untitled

Sep 25th, 2022
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function fruitShop(input) {
  2.     let monFri = new Map([
  3.         ['banana', 2.50],
  4.         ['apple', 1.20],
  5.         ['orange', 0.85],
  6.         ['grapefruit', 1.45],
  7.         ['kiwi', 2.70],
  8.         ['pineapple', 5.50],
  9.         ['grapes', 3.85]
  10.     ]);
  11.     let satSun = new Map([
  12.         ['banana', 2.70],
  13.         ['apple', 1.25],
  14.         ['orange', 0.90],
  15.         ['grapefruit', 1.60],
  16.         ['kiwi', 3.00],
  17.         ['pineapple', 5.60],
  18.         ['grapes', 4.20]
  19.     ]);
  20.     let fruitS = ['banana', 'apple', 'orange', 'grapefruit', 'kiwi', 'pineapple', 'grapes'];
  21.     let workWeek = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday'];
  22.     let weekEnd = ['Saturday', 'Sunday'];
  23.  
  24.     let fruit = input[0];
  25.     let day = input[1];
  26.     let qty = Number(input[2]);
  27.  
  28.     if (workWeek.includes(`${day}`) && fruitS.includes(`${fruit}`)) {
  29.         console.log((monFri.get(fruit) * qty).toFixed(2));
  30.     } else if (weekEnd.includes(`${day}`) && fruitS.includes(`${fruit}`)){
  31.         console.log((satSun.get(fruit) * qty).toFixed(2));
  32.     } else {
  33.         console.log('error');
  34.     }
  35. }
  36.  
  37. fruitShop(['beer', 'Tuesday', '2']);
Add Comment
Please, Sign In to add comment