let calc = (function () {
let value = 0;
function setValue(val) {
value = parseFloat(val.toFixed(2));
return this
}
function plusVal(val) {
value = parseFloat((value += val).toFixed(2));
return this
}
function getValue() {
return value
}
return {
setValue,
plusVal,
getValue
}
})();
console.log(calc.setValue(10).plusVal(30).getValue())
https://learn.javascript.ru/task/chain-calls