Question: Modify the code in the library.js file so it contains a class named Calculator. This class should have a constructor which defines properties for both
Modify the code in the library.js file so it contains a class named Calculator. This class should
have a constructor which defines properties for both input values.
The class should also have methods, for each of the math operations. If both values are valid
then each function should return the result of the calculation. If the results are not valid, it
should throw an exception.
Modify the claculate.js file to create and use an object from the Calculator class. Then use the
object to perform the calculations when each of the buttons are pressed.
Note that you should still validate the user entries to prevent an exception from being thrown.
Library.js:
"use strict";
calculate.js:
"use strict";
$documentready
$#addition"click
let value parseInt$#valueval;
let value parseInt$#valueval;
if isNaNvalue isNaNvalue
alertPlease make sure both values are valid integers";
else
$#result"valvalue value;
;
$#subtraction"click
let value parseInt$#valueval;
let value parseInt$#valueval;
if isNaNvalue isNaNvalue
alertPlease make sure both values are valid integers";
else
$#result"valvalue value;
$#division"click
let value parseInt$#valueval;
let value parseInt$#valueval;
if isNaNvalue isNaNvalue
alertPlease make sure both values are valid integers";
else
$#result"valvalue value;
$#multiplication"click
let value parseInt$#valueval;
let value parseInt$#valueval;
if isNaNvalue isNaNvalue
alertPlease make sure both values are valid integers";
else
$#result"valvalue value;
$#cents"focus;
;
index.html:
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
