Ledger Nano X - The secure hardware wallet
SHARE
TWEET

operation between numbers

Elpida3006 Apr 10th, 2020 163 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solve(n1,n2,operator) {
  2.  
  3.     n1 = Number(n1);
  4.     n2 = Number(n2);
  5.     operator = operator;
  6.     let result = 0;
  7.     let evenOdd = 0;
  8.    
  9.     switch(operator) {
  10.         case "+": result = n1 + n2; break;
  11.         case "-": result = n1 - n2; break;
  12.         case "*": result = n1 * n2; break;
  13.         case "/": result = n1 / n2; break;
  14.         case "%": result = n1 % n2; break;
  15.     }
  16.     if (operator == "+" || operator == "-" || operator == "*") {
  17.         if (result % 2 == 0) {
  18.          evenOdd
  19.          = "even";
  20.         } else {
  21.          evenOdd
  22.          = "odd";
  23.         } console.log(`${n1} ${operator} ${n2} = ${result} - ${evenOdd}`)
  24.     } else if (operator == "/" || operator == "%") {
  25.         if (n2 == 0) {
  26.             console.log(`Cannot divide ${n1} by zero`);
  27.         } else {
  28.             // console.log(`${n1} ${operator} ${n2} = ${result}`);
  29.             console.log(`${n1} ${operator} ${n2} = ${(n1 % n2)}`);
  30.         }
  31.     }
  32.    
  33.    
  34.     }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top