diff --git a/src/makeRobotAccountant.js b/src/makeRobotAccountant.js index 38b9758a..146cd00b 100644 --- a/src/makeRobotAccountant.js +++ b/src/makeRobotAccountant.js @@ -6,7 +6,23 @@ */ function makeRobotAccountant() { - // write code here + let calls = 0; + + const innerFunction = function(y) { + return function(x) { + calls++; + + if (calls <= 3 || calls % 2 !== 0) { + return x + y; + } + + return 'Bzzz... Error!'; + }; + }; + + return function(x) { + return innerFunction(x); + }; } module.exports = makeRobotAccountant;