Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function operationsBetweenNumbers(input) {
- let N1 = Number(input[0]);
- let N2 = Number(input[1]);
- let operator = input[2];
- let result = 0;
- if (operator === "+") {
- result = N1 + N2;
- if (result % 2 == 0) {
- console.log(`${N1} + ${N2} = ${result} - even`);
- } else {
- console.log(`${N1} - ${N2} = ${result} - odd`);
- }
- } else if (operator === "-") {
- result = N1 - N2;
- if (result % 2 == 0) {
- console.log(`${N1} - ${N2} = ${result} - even`);
- } else {
- console.log(`${N1} - ${N2} = ${result} - odd`);
- }
- } else if (operator === "*") {
- result = N1 * N2;
- if (result % 2 === 0) {
- console.log(`${N1} * ${N2} = ${result} - even`);
- } else {
- console.log(`${N1} * ${N2} = ${result} - odd`);
- }
- } else if (operator === "/") {
- if (N2 === 0) {
- console.log(`Cannot divide ${N1} by zero`);
- } else {
- result = N1 / N2;
- console.log(`${N1} / ${N2} = ${result.toFixed(2)}`);
- }
- } else if (operator === "%") {
- if (N2 === 0) {
- console.log(`Cannot divide ${N1} by zero`);
- } else {
- result = N1 % N2;
- console.log(`${N1} % ${N2} = ${result}`);
- }
- }
- }
Add Comment
Please, Sign In to add comment