-
Notifications
You must be signed in to change notification settings - Fork 2.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
All tests are completed #2378
base: master
Are you sure you want to change the base?
All tests are completed #2378
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,23 @@ | |
*/ | ||
|
||
function makeRobotAccountant() { | ||
// write code here | ||
let count = 0; | ||
|
||
function getSum(number) { | ||
return function(value) { | ||
count++; | ||
|
||
const result = value + number; | ||
|
||
if (count % 2 === 0 && count > 3) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider combining the conditions in the if statement to avoid nesting ternary operators or multiple if-else statements. Since you're only checking one condition, it's not necessary to use an else statement; you can return |
||
return 'Bzzz... Error!'; | ||
} else { | ||
return result; | ||
} | ||
}; | ||
} | ||
Comment on lines
+11
to
+23
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The inner function returned by |
||
|
||
return getSum; | ||
} | ||
|
||
module.exports = makeRobotAccountant; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should use one variable for counting function calls. Here, you are using
count
correctly to keep track of the calls to the returned function.