Guest User

Untitled

a guest
Dec 13th, 2018
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.81 KB | None | 0 0
  1. class CashAmount {
  2. constructor(amount){
  3. this.value = amount;
  4. }
  5.  
  6. totalInPennies() {
  7. var string = String(this.value);
  8. if (!string.includes('.')){
  9. string = string + '00';
  10. }
  11. var pennies = '';
  12. for (let i = 0; i < string.length; i++){
  13. if (string[i] !== '.'){
  14. pennies += string[i];
  15. }
  16. }
  17. return Number(pennies);
  18. }
  19.  
  20. addDoubleAmount(val) {
  21. var total = String(this.totalInPennies(val) + this.totalInPennies(this.value));
  22. total = Number(totla.slice(0,-2) + '.' +totla.slice(-2));
  23. return total;
  24. }
  25.  
  26. quantityOfEachDenomination() {
  27. var obj = {};
  28. var value = totalInPennies(this.amount);
  29. if (value > 10000) {
  30. obj['hundreds'] = Math.floor(value/10000);
  31. value = value % 10000;
  32. }
  33. if (value > 5000) {
  34. obj['fifties'] = 1;
  35. value = value - 5000;
  36. }
  37. if (value > 2000) {
  38. obj['twenties'] = Math.floor(value/2000);
  39. value = value % 2000;
  40. }
  41. if (value > 1000) {
  42. obj['tens'] = 1;
  43. value = value - 1000;
  44. }
  45. if (value > 500) {
  46. obj['fives'] = 1;
  47. value = value - 500;
  48. }
  49. if (value > 100) {
  50. obj['ones'] = Math.floor(value/100);;
  51. value = value % 100;
  52. }
  53. if (value > 25) {
  54. obj['quarter'] = Math.floor(value/25);;
  55. value = value % 25;
  56. }
  57. if (value > 10) {
  58. obj['dimes'] = Math.floor(value/10);;
  59. value = value % 100;
  60. }
  61. if (value > 5) {
  62. obj['nickles'] = 1;;
  63. value = value - 5;
  64. }
  65. obj[pennies] = value;
  66. return obj;
  67. }
  68.  
  69. toDouble() {
  70. var value = String(totalInPennies(this.value))
  71. value = Number(totla.slice(0,-2) + '.' +totla.slice(-2));
  72. return value;
  73.  
  74. }
  75.  
  76. toDoubleString() {
  77. var value = String(totalInPennies(this.value))
  78. value = totla.slice(0,-2) + '.' +totla.slice(-2);
  79. return value;
  80. }
  81.  
  82. }
Add Comment
Please, Sign In to add comment