Calculator

by fredericklim

JavaScript

let calculator = {
   x: 0,
   y: 0,
   read: () => {
      this.x = prompt("Please input 1st number:");
      this.y = prompt("Please input 2nd number:");
   },
   sum: () => {
      return parseInt(this.x) + parseInt(this.y);
   },
   mul: () => {
      return parseInt(this.x) * parseInt(this.y);
   }
}

calculator.read();
alert( calculator.sum() );
alert( calculator.mul() );