en.javascript.info/1-js/04-object-basics/06-constructor-new/2-calculator-constructor/solution.md
Ilya Kantor 20784e7f26 up
2017-02-19 01:41:36 +03:00

390 B

function Calculator() {

  this.read = function() {
    this.a = +prompt('a?', 0);
    this.b = +prompt('b?', 0);
  };

  this.sum = function() {
    return this.a + this.b;
  };

  this.mul = function() {
    return this.a * this.b;
  };
}

let calculator = new Calculator();
calculator.read();

alert( "Sum=" + calculator.sum() );
alert( "Mul=" + calculator.mul() );