Skip to content

Commit

Permalink
task solution
Browse files Browse the repository at this point in the history
  • Loading branch information
Kacper7001 committed Mar 10, 2024
1 parent 9b9a80d commit 59efc7a
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion src/makeRobotAccountant.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
} else {
return 'Bzzz... Error!';
}
};
};

return function(x) {
return innerFunction(x);
};
}

module.exports = makeRobotAccountant;

0 comments on commit 59efc7a

Please sign in to comment.