Skip to content

Commit add8374

Browse files
committed
moved files into src directory
1 parent 812e2de commit add8374

File tree

4 files changed

+1102
-0
lines changed

4 files changed

+1102
-0
lines changed

src/calculator.ico

14.7 KB
Binary file not shown.

src/calculator.js

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
function add(num1, num2) {
2+
return num1 + num2;
3+
}
4+
function subtract(num1, num2) {
5+
return num1 - num2;
6+
}
7+
function multiply(num1, num2) {
8+
return num1 * num2;
9+
}
10+
function divide(num1, num2) {
11+
return num1 / num2;
12+
}
13+
14+
function tipFormCalc(total, splitByNumber, tipPercetage) {
15+
let subTotal = multiply(total, add(1, divide(tipPercetage, 100)));
16+
17+
return splitByNumber !== 0 ? divide(subTotal, splitByNumber) : subTotal;
18+
}
19+
20+
function discountFormCalc(itemPrice, discountPercentage, taxPercentage) {
21+
//to do review feedback received on the calc!
22+
let discountSubTotal = divide(
23+
itemPrice,
24+
add(1, divide(discountPercentage, 100)),
25+
);
26+
27+
return multiply(discountSubTotal, add(1, divide(taxPercentage, 100)));
28+
}
29+
30+
function calculate(num1, operation, num2) {
31+
try {
32+
return operation(num1, num2);
33+
} catch (error) {
34+
console.log(error);
35+
}
36+
}
37+
38+
export {
39+
add,
40+
subtract,
41+
multiply,
42+
divide,
43+
tipFormCalc,
44+
discountFormCalc,
45+
calculate,
46+
};

0 commit comments

Comments
 (0)