Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class CashAmount {
- constructor(amount){
- this.value = amount;
- }
- totalInPennies() {
- var string = String(this.value);
- if (!string.includes('.')){
- string = string + '00';
- }
- var pennies = '';
- for (let i = 0; i < string.length; i++){
- if (string[i] !== '.'){
- pennies += string[i];
- }
- }
- return Number(pennies);
- }
- addDoubleAmount(val) {
- var total = String(this.totalInPennies(val) + this.totalInPennies(this.value));
- total = Number(totla.slice(0,-2) + '.' +totla.slice(-2));
- return total;
- }
- quantityOfEachDenomination() {
- var obj = {};
- var value = totalInPennies(this.amount);
- if (value > 10000) {
- obj['hundreds'] = Math.floor(value/10000);
- value = value % 10000;
- }
- if (value > 5000) {
- obj['fifties'] = 1;
- value = value - 5000;
- }
- if (value > 2000) {
- obj['twenties'] = Math.floor(value/2000);
- value = value % 2000;
- }
- if (value > 1000) {
- obj['tens'] = 1;
- value = value - 1000;
- }
- if (value > 500) {
- obj['fives'] = 1;
- value = value - 500;
- }
- if (value > 100) {
- obj['ones'] = Math.floor(value/100);;
- value = value % 100;
- }
- if (value > 25) {
- obj['quarter'] = Math.floor(value/25);;
- value = value % 25;
- }
- if (value > 10) {
- obj['dimes'] = Math.floor(value/10);;
- value = value % 100;
- }
- if (value > 5) {
- obj['nickles'] = 1;;
- value = value - 5;
- }
- obj[pennies] = value;
- return obj;
- }
- toDouble() {
- var value = String(totalInPennies(this.value))
- value = Number(totla.slice(0,-2) + '.' +totla.slice(-2));
- return value;
- }
- toDoubleString() {
- var value = String(totalInPennies(this.value))
- value = totla.slice(0,-2) + '.' +totla.slice(-2);
- return value;
- }
- }
Add Comment
Please, Sign In to add comment