Advertisement
fbinnzhivko

fokus

Sep 25th, 2016
305
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function circleArea(input) {
  2.  
  3.     n = input.map(String);
  4.     let repeats = input[0];
  5.  
  6.     var real = n.splice(1, n.length);
  7.     let totalMoney = 0.0;
  8.  
  9.     if (repeats == 0) {
  10.         console.log('The price for the coffee is: $0' );
  11.         console.log('Total: $0' );
  12.     }
  13.     if (repeats > 0) {
  14.         for (i = 0; i < repeats; i++) {
  15.  
  16.             var pricePerCapsule = Number.parseFloat(real[i]);
  17.             var date = real[i + 1].split('/');
  18.             var capsulesCount = parseInt(real[i + 2]);
  19.             let diffDays = new Date(Date.UTC(date[2], date[1], 0));
  20.             let price = (diffDays.getDate() * capsulesCount) * pricePerCapsule;
  21.  
  22.             console.log('The price for the coffee is: $' + price.toFixed(2));
  23.             totalMoney = totalMoney + price;
  24.             real.splice(0, 2)
  25.         }
  26.         console.log('Total: $' + totalMoney.toFixed(2));
  27.     }
  28. }
  29. // circleArea(['0']);
  30. // circleArea(['1', '1.53', '06/06/2016', '8']);
  31. // circleArea(['1', '1.53', '06/06/2016', '8']);
  32. //circleArea(['2', '7922816251426433759354395033', '6/02/1960', '2147483646', '7922816251426433759354395033', '03/01/1980', '2147483646']);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement