Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Prompt: tackling floating-point imprecision with the CashAmount class
- function CashAmount(amount) {
- this.amount = amount;
- }
- CashAmount.prototype.totalInPennies = function() {
- return this.amount * 100;
- }
- CashAmount.prototype.addDoubleAmount = function(addAmount) {
- this.amount = Math.ceil( (this.amount * 100) + (addAmount * 100) ) / 100;
- return this.amount;
- }
- CashAmount.prototype.toDouble = function() {
- return this.amount;
- }
- CashAmount.prototype.toDoubleString = function() {
- return JSON.stringify(this.amountt);
- }
- CashAmount.prototype.quantityOfEachDenomination = function() {
- }
- // class TestSuite {
- // runTests() {
- // // your code here
- // }
- // testFoo() { /* some test code */ }
- // testBar() { /* some test code */ }
- // testBaz() { /* some test code */ }
- // }
- // const suite = new TestSuite();
- // suite.runTests(); // testFoo, testBar, and testBaz are executed
- // var cash = new CashAmount(11.22)
- // console.log('totalIn Pennies ',cash.totalInPennies())
- // console.log(cash.addDoubleAmount(29.33))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement