Skip to content
Open

Dev #2363

Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 8 additions & 25 deletions src/calculator.js
Original file line number Diff line number Diff line change
@@ -1,47 +1,30 @@
exports._check = () => {
Copy link
Collaborator

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)

// DRY up the codebase with this function
// First, move the duplicate error checking code here
// Then, invoke this function inside each of the others
// HINT: you can invoke this function with exports._check()
};

exports.add = (x, y) => {

Copy link
Collaborator

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 x !== 'number') {
throw new TypeError(`${x} is not a number`);
Copy link
Collaborator

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)

Copy link
Collaborator

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

}
if (typeof y !== 'number') {
throw new TypeError(`${y} is not a number`);
Copy link
Collaborator

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)

}
};

exports.add = (x, y) => {
exports._check(x, y)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing semicolon.
(learn more)

return x + y;
};

exports.subtract = (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`);
}
exports._check(x, y)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing semicolon.
(learn more)

return x - y;
};

exports.multiply = (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`);
}
exports._check(x, y)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing semicolon.
(learn more)

return x * y;
};

exports.divide = (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`);
}
exports._check(x, y)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing semicolon.
(learn more)

return x / y;
};

Expand Down