Advertisement
AviEzerzer

Untitled

Sep 17th, 2018
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function tipCalculator(bill) {
  2.  
  3.     /**optional */
  4.     if (bill < 0 || isNaN(bill)) {
  5.         console.log('oops')
  6.         return NaN;
  7.     };
  8.     /*** */
  9.  
  10.     let tip;
  11.     switch (true) {
  12.  
  13.         case (bill < 50):
  14.             tip = bill * 0.2;
  15.             break;
  16.  
  17.         case (bill >= 50 && bill <= 200):
  18.             tip = bill * 0.15;
  19.             break;
  20.  
  21.         default:
  22.             tip = bill * 0.1;
  23.             break;
  24.  
  25.     }
  26.     return tip;
  27. }
  28.  
  29. var bills = [124, 48, 268];
  30. var AmountDue = bills.map(bill => (bill + tipCalculator(bill)).toFixed(2));
  31. console.log(AmountDue)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement