Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save betterkenly/6067d80d10aa629cae1bdad8bf8e4509 to your computer and use it in GitHub Desktop.
Save betterkenly/6067d80d10aa629cae1bdad8bf8e4509 to your computer and use it in GitHub Desktop.
interview prop
// var cashAmount = function(value) {
// this.value = value;
// }
// cashAmount.prototype.totalInPennies = function() {
// return this.value * 100;
// }
// const cash = new cashAmount(10.50);
// cash.totalInPennies(); // -> 1050
class CashAmount {
constructor(value) {
this.value = value;
this.pennies = this.value * 100;
}
totalInPennies (){
return this.pennies;
}
addDoubleAmount(value) {
this.pennies = this.pennies + value * 100;
}
quantityOfEachDenomination () {
let result = {};
let dollars = [100, 50, 20, 10, 5, 1];
let cents = [50, 25, 10, 5, 1];
return result;
}
toDouble() {
return this.pennies / 100;
}
toDoubleString() {
return (this.pennies / 100).toString();
}
}
const cash = new CashAmount(10.50);
cash.addDoubleAmount(29.33);
cash.totalInPennies(); // -> 3983
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment