Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function mathOperations(num1, num2, sign) {
- const operations = {
- '+': (a, b) => a + b,
- '-': (a, b) => a - b,
- '*': (a, b) => a * b,
- '/': (a, b) => a / b,
- '%': (a, b) => a % b,
- '**': (a, b) => a ** b
- };
- const result = operations[sign](num1, num2);
- console.log(result);
- }
- OR
- function mathOperations(num1, num2, sign) {
- let result = 0;
- if (sign === '+') {
- result = num1 + num2;
- } else if (sign === '-') {
- result = num1 - num2;
- } else if (sign === '*') {
- result = num1 * num2;
- } else if (sign === '/') {
- result = num1 / num2;
- } else if (sign === '%') {
- result = num1 % num2;
- } else if (sign === '**') {
- result = Math.pow(num1, num2);
- }
- console.log(result);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement