Home
← All questions

Chainable calculator in JavaScript

EasyPremiumJavaScript

Asked at Publicis Sapient · Meesho

JavaScript interview practice: Build a calculator supporting method chaining: calculator.add(3).multiply(4).subtract(5).getValue().

Problem

Implement a calculator that supports method chaining for add, subtract, and multiply, and a getValue() to read the result.

// calculator.add(10).subtract(2).multiply(3).getValue() === 24
Premium question

Unlock the in-browser editor, test cases, and model solution with Mentoxis Premium.

Unlock with Premium