Calculator Program In JS
Using Constructor
by SriSri M
JavaScript
function Calc() {
this.read = function() {
this.a = +prompt("a is:",0);
this.b = +prompt("b is:",0);
}
this.sum = function() {
return this.a + this.b;
}
this.minus = function() {
return this.a - this.b;
}
}
let cal = new Calc();
cal.read();
console.log(cal.sum());
console.log(cal.minus());