Advertisement
Guest User

Untitled

a guest
Feb 23rd, 2020
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.39 KB | None | 0 0
  1. function operationsBetweenNumber(input) {
  2. let n1 = Number(input.shift());
  3. let n2 = Number(input.shift());
  4. let symbol = input.shift();
  5.  
  6.  
  7.  
  8. switch (symbol) {
  9. case `*`:
  10. if ((n1 * n2) % 2 == 0) {
  11. console.log(`${n1} * ${n2} = ${n1 * n2} - even`);
  12. } else {
  13. console.log(`${n1} * ${n2} = ${n1 * n2} - odd`);
  14. }
  15. break;
  16. case '+':
  17. if ((n1 + n2) % 2 == 0) {
  18. console.log(`${n1} + ${n2} = ${n1 + n2} - even`);
  19. } else {
  20. console.log(`${n1} + ${n2} = ${n1 + n2} - odd`);
  21. }
  22. break;
  23. case `-`:
  24. if ((n1 - n2) % 2 == 0) {
  25. console.log(`${n1} - ${n2} = ${n1 - n2} - even`);
  26. } else {
  27. console.log(`${n1} - ${n2} = ${n1 - n2} - odd`);
  28. }
  29. break;
  30. case `/`:
  31. if (n2 == 0 && symbol == '/'){
  32. console.log(`Cannot divide ${n1} by zero`);
  33. } else {
  34. console.log(`${n1} / ${n2} = ${(n1 / n2).toFixed(2)}`);
  35. }
  36. break;
  37. case `%`:
  38. if (n2 == 0 && symbol == `%`) {
  39. console.log(`Cannot divide ${n1} by zero`);
  40. } else {
  41. console.log(`${n1} % ${n2} = ${n1 % n2}`);
  42. }
  43. break;
  44. }
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement