TZinovieva

Operations Between Numbers 100/100

May 23rd, 2022 (edited)
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function operationsBetweenNumbers(input) {
  2.     let N1 = Number(input[0]);
  3.     let N2 = Number(input[1]);
  4.     let operator = input[2];
  5.  
  6.         let result = 0;
  7.     if (operator === "+") {
  8.         result = N1 + N2;
  9.         if (result % 2 == 0) {
  10.         console.log(`${N1} + ${N2} = ${result} - even`);
  11.         } else {
  12.                 console.log(`${N1} - ${N2} = ${result} - odd`);  
  13.         }
  14.     } else if (operator === "-") {
  15.         result = N1 - N2;
  16.         if (result % 2 == 0) {
  17.             console.log(`${N1} - ${N2} = ${result} - even`);
  18.             } else {
  19.             console.log(`${N1} - ${N2} = ${result} - odd`);  
  20.             }
  21.     } else if (operator === "*") {
  22.         result = N1 * N2;
  23.         if (result % 2 === 0) {
  24.         console.log(`${N1} * ${N2} = ${result} - even`);
  25.             } else {
  26.             console.log(`${N1} * ${N2} = ${result} - odd`);  
  27.             }
  28.     } else if (operator === "/") {
  29.         if (N2 === 0) {
  30.             console.log(`Cannot divide ${N1} by zero`);
  31.         } else {
  32.             result = N1 / N2;
  33.             console.log(`${N1} / ${N2} = ${result.toFixed(2)}`);
  34.         }
  35.     } else if (operator === "%") {
  36.         if (N2 === 0) {
  37.             console.log(`Cannot divide ${N1} by zero`);
  38.         } else {
  39.         result = N1 % N2;
  40.         console.log(`${N1} % ${N2} = ${result}`);
  41. }
  42. }
  43. }
Add Comment
Please, Sign In to add comment