-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Dev #2363
base: vijaytakbhate2002
Are you sure you want to change the base?
Dev #2363
Conversation
Thank you for the submission, @vijaytakbhate2002! I'll review your code shortly, hang tight. |
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.
This is a great attempt, @vijaytakbhate2002!
I would like to request a few changes before merging your work. Please review my comments below and make the appropriate changes to your code.
After you update your code locally, follow the instructions to save your changes locally and push your changes to your fork.
When you push your changes to your fork, I'll come back for another review.
There are 8 style guide violations in your contribution. I've marked them with inline comments for your convenience.
Please revisit your code and follow the style guide best practices.
Hint: You might be able to fix some issues automatically by running npm run lint -- --fix
There are 5 tests still pending. In your test file, change describe.skip
to describe
and ensure they pass.
There are 16 tests failing. Please revisit your code and make the failing tests pass.
❌ add should throw a TypeError if arguments are not numbers
-actual
+expected
-ReferenceError: x is not defined
+TypeError
AssertionError: expected [Function] to throw 'TypeError' but 'ReferenceError: x is not defined' was thrown
at Context.<anonymous> (src/calculator.test.js:49:51)
at processImmediate (node:internal/timers:464:21)
❌ add should add two positive numbers
ReferenceError: x is not defined
at Object.exports._check (src/calculator.js:4:28)
at Object.exports.add (src/calculator.js:12:11)
at Context.<anonymous> (src/calculator.test.js:58:23)
at processImmediate (node:internal/timers:464:21)
❌ add should add two negative numbers
ReferenceError: x is not defined
at Object.exports._check (src/calculator.js:4:28)
at Object.exports.add (src/calculator.js:12:11)
at Context.<anonymous> (src/calculator.test.js:62:23)
at processImmediate (node:internal/timers:464:21)
❌ add should add one positive number and one negative number
ReferenceError: x is not defined
at Object.exports._check (src/calculator.js:4:28)
at Object.exports.add (src/calculator.js:12:11)
at Context.<anonymous> (src/calculator.test.js:66:23)
at processImmediate (node:internal/timers:464:21)
❌ subtract should throw a TypeError if arguments are not numbers
-actual
+expected
-ReferenceError: x is not defined
+TypeError
AssertionError: expected [Function] to throw 'TypeError' but 'ReferenceError: x is not defined' was thrown
at Context.<anonymous> (src/calculator.test.js:72:56)
at processImmediate (node:internal/timers:464:21)
❌ subtract should subtract two positive numbers
ReferenceError: x is not defined
at Object.exports._check (src/calculator.js:4:28)
at Object.exports.subtract (src/calculator.js:17:11)
at Context.<anonymous> (src/calculator.test.js:81:23)
at processImmediate (node:internal/timers:464:21)
❌ subtract should subtract two negative numbers
ReferenceError: x is not defined
at Object.exports._check (src/calculator.js:4:28)
at Object.exports.subtract (src/calculator.js:17:11)
at Context.<anonymous> (src/calculator.test.js:85:23)
at processImmediate (node:internal/timers:464:21)
❌ subtract should subtract one positive number and one negative number
ReferenceError: x is not defined
at Object.exports._check (src/calculator.js:4:28)
at Object.exports.subtract (src/calculator.js:17:11)
at Context.<anonymous> (src/calculator.test.js:89:23)
at processImmediate (node:internal/timers:464:21)
❌ multiply should throw a TypeError if arguments are not numbers
-actual
+expected
-ReferenceError: x is not defined
+TypeError
AssertionError: expected [Function] to throw 'TypeError' but 'ReferenceError: x is not defined' was thrown
at Context.<anonymous> (src/calculator.test.js:95:56)
at processImmediate (node:internal/timers:464:21)
❌ multiply should multiply two positive numbers
ReferenceError: x is not defined
at Object.exports._check (src/calculator.js:4:28)
at Object.exports.multiply (src/calculator.js:22:11)
at Context.<anonymous> (src/calculator.test.js:104:23)
at processImmediate (node:internal/timers:464:21)
❌ multiply should multiply two negative numbers
ReferenceError: x is not defined
at Object.exports._check (src/calculator.js:4:28)
at Object.exports.multiply (src/calculator.js:22:11)
at Context.<anonymous> (src/calculator.test.js:108:23)
at processImmediate (node:internal/timers:464:21)
❌ multiply should multiply one positive number and one negative number
ReferenceError: x is not defined
at Object.exports._check (src/calculator.js:4:28)
at Object.exports.multiply (src/calculator.js:22:11)
at Context.<anonymous> (src/calculator.test.js:112:23)
at processImmediate (node:internal/timers:464:21)
❌ divide should throw a TypeError if arguments are not numbers
-actual
+expected
-ReferenceError: x is not defined
+TypeError
AssertionError: expected [Function] to throw 'TypeError' but 'ReferenceError: x is not defined' was thrown
at Context.<anonymous> (src/calculator.test.js:118:54)
at processImmediate (node:internal/timers:464:21)
❌ divide should divide two positive numbers
ReferenceError: x is not defined
at Object.exports._check (src/calculator.js:4:28)
at Object.exports.divide (src/calculator.js:27:11)
at Context.<anonymous> (src/calculator.test.js:127:23)
at processImmediate (node:internal/timers:464:21)
❌ divide should divide two negative numbers
ReferenceError: x is not defined
at Object.exports._check (src/calculator.js:4:28)
at Object.exports.divide (src/calculator.js:27:11)
at Context.<anonymous> (src/calculator.test.js:131:23)
at processImmediate (node:internal/timers:464:21)
❌ divide should divide one positive number and one negative number
ReferenceError: x is not defined
at Object.exports._check (src/calculator.js:4:28)
at Object.exports.divide (src/calculator.js:27:11)
at Context.<anonymous> (src/calculator.test.js:135:23)
at processImmediate (node:internal/timers:464:21)
src/calculator.js
Outdated
@@ -1,47 +1,30 @@ | |||
exports._check = () => { |
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.
Block must not be padded by blank lines.
(learn more)
src/calculator.js
Outdated
}; | ||
|
||
exports.add = (x, y) => { | ||
|
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.
Trailing spaces not allowed.
(learn more)
}; | ||
|
||
exports.add = (x, y) => { | ||
|
||
if (typeof x !== 'number') { | ||
throw new TypeError(`${x} is not a number`); |
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.
'x' is not defined.
(learn more)
}; | ||
|
||
exports.add = (x, y) => { | ||
|
||
if (typeof x !== 'number') { | ||
throw new TypeError(`${x} is not a number`); | ||
} | ||
if (typeof y !== 'number') { | ||
throw new TypeError(`${y} is not a number`); |
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.
'y' is not defined.
(learn more)
src/calculator.js
Outdated
}; | ||
|
||
exports.add = (x, y) => { | ||
exports._check(x, y) |
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.
Missing semicolon.
(learn more)
src/calculator.js
Outdated
if (typeof y !== 'number') { | ||
throw new TypeError(`${y} is not a number`); | ||
} | ||
exports._check(x, y) |
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.
Missing semicolon.
(learn more)
src/calculator.js
Outdated
if (typeof y !== 'number') { | ||
throw new TypeError(`${y} is not a number`); | ||
} | ||
exports._check(x, y) |
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.
Missing semicolon.
(learn more)
src/calculator.js
Outdated
if (typeof y !== 'number') { | ||
throw new TypeError(`${y} is not a number`); | ||
} | ||
exports._check(x, y) |
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.
Missing semicolon.
(learn more)
}; | ||
|
||
exports.add = (x, y) => { | ||
|
||
if (typeof x !== 'number') { | ||
throw new TypeError(`${x} is not a number`); |
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.
This line is responsible for 12 failing tests. Run npm test
and see if you can figure out why.
❌ add should add two positive numbers
❌ add should add two negative numbers
❌ add should add one positive number and one negative number
❌ subtract should subtract two positive numbers
❌ subtract should subtract two negative numbers
❌ subtract should subtract one positive number and one negative number
❌ multiply should multiply two positive numbers
❌ multiply should multiply two negative numbers
❌ multiply should multiply one positive number and one negative number
❌ divide should divide two positive numbers
❌ divide should divide two negative numbers
❌ divide should divide one positive number and one negative number
Thanks for the changes, @vijaytakbhate2002. I'm reviewing them now. |
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.
This is a great attempt, @vijaytakbhate2002!
I would like to request a few changes before merging your work. Please review my comments below and make the appropriate changes to your code.
After you update your code locally, follow the instructions to save your changes locally and push your changes to your fork.
When you push your changes to your fork, I'll come back for another review.
There are 10 style guide violations in your contribution. I've marked them with inline comments for your convenience.
Please revisit your code and follow the style guide best practices.
Hint: You might be able to fix some issues automatically by running npm run lint -- --fix
There are 5 tests still pending. In your test file, change describe.skip
to describe
and ensure they pass.
}; | ||
|
||
exports.add = (x, y) => { | ||
exports._check(x, y); |
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.
Trailing spaces not allowed.
(learn more)
|
||
exports.add = (x, y) => { | ||
exports._check(x, y); | ||
return x + y; |
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.
Trailing spaces not allowed.
(learn more)
throw new TypeError(`${y} is not a number`); | ||
} | ||
return x - y; | ||
exports._check(x, y); |
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.
Trailing spaces not allowed.
(learn more)
} | ||
return x - y; | ||
exports._check(x, y); | ||
return x - y; |
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.
Trailing spaces not allowed.
(learn more)
throw new TypeError(`${y} is not a number`); | ||
} | ||
return x * y; | ||
exports._check(x, y); |
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.
Trailing spaces not allowed.
(learn more)
} | ||
return x * y; | ||
exports._check(x, y); | ||
return x * y; |
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.
Trailing spaces not allowed.
(learn more)
} | ||
if (typeof y !== 'number') { | ||
throw new TypeError(`${y} is not a number`); | ||
exports._check(x, y); |
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.
Trailing spaces not allowed.
(learn more)
if (typeof y !== 'number') { | ||
throw new TypeError(`${y} is not a number`); | ||
exports._check(x, y); | ||
if (y === 0) { |
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.
Trailing spaces not allowed.
(learn more)
throw new TypeError(`${y} is not a number`); | ||
exports._check(x, y); | ||
if (y === 0) { | ||
throw new Error("Cannot divide by zero"); |
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.
Strings must use singlequote.
(learn more)
} | ||
return x / y; | ||
return x / y; |
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.
Trailing spaces not allowed.
(learn more)
Hey maintainer,
I added Error checking code in _check function and invoked that function to other functions (add, subtract, multiply, divide). Removed Error checking code from these functions.
Here is before and after image of code change
Before
After