# Builder patterin in JavaScript # ``` class Calculator { constructor(props){ this.result = 0 ; } add(number1, number 2){ this.result = number1 + number2 ; return this ; } subtract(n1,n2){ this.result = n1 -n2 ; return this; } divide(n1,n2){ this.result = n1 / n2 ; return this; } multiply(n1,n2){ this.result = n1 * n2 ; return this; } getResult(){ return this.result; } } //Calling calculator to sum twonumber; let calculator = new Calculator() let result = calculator.add(5,10).getResult() ```
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up