Created
March 18, 2021 16:32
-
-
Save parasdaryanani/b738d2dd912d932f9a429e4e70c8237b to your computer and use it in GitHub Desktop.
Calculate profit through chain methods
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export default class Calculator { | |
constructor() { | |
this.value = 0; | |
} | |
revenue(value) { | |
this.value = value; | |
return this; | |
} | |
deductTax(percentage) { | |
this.value = this.value - (percentage * this.value) / 100; | |
return this; | |
} | |
// EU VAT convenience method | |
deductVAT(percentage = 20) { | |
return this.deductTax(percentage); | |
} | |
// UK Corporation tax convenience method | |
deductCorpTax(percentage = 20) { | |
return this.deductTax(percentage); | |
} | |
deductCost(value) { | |
this.value = this.value - value; | |
return this; | |
} | |
} | |
// const a = new Calculator() | |
// .revenue(1250) | |
// .deductVAT() | |
// .deductCorpTax(); | |
// console.log(a.value); | |
// Console Output | |
// 800 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment