krustev_84

Untitled

Feb 19th, 2020
176
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.15 KB | None | 0 0
  1. function operators(input)
  2. {
  3. let N1 = Number(input.shift());
  4. let N2 = Number(input.shift());
  5. let nOperator = input.shift();
  6.  
  7. let result = 0;
  8. let output = ``;
  9.  
  10.  
  11. if ( N2 == 0 && (nOperator === '/' || nOperator === '%'))
  12. {
  13. output = `Cannot divide ${N1} by zero`;
  14. }
  15. else if ( nOperator === '/')
  16. {
  17. result = N1 / N2;
  18. output = `${N1} ${nOperator} ${N2} = ${result}`;
  19. }
  20. else if (nOperator === '%')
  21. {
  22. result = N1 % N2;
  23. output = `${N1} ${nOperator} ${N2} = ${result}`;
  24. }
  25. else
  26. {
  27. if (nOperator === '+')
  28. {
  29. result = N1 + N2;
  30. }
  31. else if (nOperator ==='-')
  32. {
  33. result = N1 - N2;
  34. }
  35. else if (nOperator === '*')
  36. {
  37. result = N1 * N2;
  38. }
  39.  
  40.  
  41.  
  42. let numberIs = '';
  43. if ( result % 2 == 0)
  44. {
  45. numberIs = 'even';
  46. }
  47. else
  48. {
  49. numberIs ='odd';
  50. }
  51.  
  52. output = `${N1} ${nOperator} ${N2} = ${result} - ${numberIs}`;
  53.  
  54.  
  55. }
  56. console.log( output );
  57.  
  58. }
Add Comment
Please, Sign In to add comment