Skip to content

cdbluejr Primary/lesson 06 Reload Expression Calculator #256

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

Closed
wants to merge 2 commits into from
Closed
Changes from all 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
20 changes: 19 additions & 1 deletion lesson_06/expression/src/expression_calculator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,25 @@ export class ExpressionCalculator {
/** Returns the calculation of ((a + b) * c) / d^e */
calculate(a: number, b: number, c: number, d: number, e: number): number {
// Implement your code here to return the correct value.
return 0;
const sum = this.add(a, b);
const pro = this.multiply(sum, c);
Copy link
Contributor

Choose a reason for hiding this comment

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

Prefer product over pro, exponent over expo, and quotient over quo. Spell out the words in your variable names unless the abbreviation is more commonly used (e.g. countryUsa instead of countryUnitedStatesOfAmerica)

const expo = this.pow(d, e);
const quo = this.divide(pro, expo);

return quo;
}

add(a: number, b: number): number {
const result = a + b;
return result;
}
multiply(a: number, b: number): number {
const prod = a * b;
return prod;
}
divide(a: number, b: number): number {
const quot = a / b;
return quot;
}

pow(base: number, exponent: number): number {
Expand Down