desito07

Calculator

May 24th, 2020
246
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.49 KB | None | 0 0
  1. function calculator(num, operator, otherNum) {
  2. if (operator === "+") {
  3. console.log((num + otherNum).toFixed(2));
  4. } else if (operator === "-") {
  5. console.log((num - otherNum).toFixed(2));
  6. } else if (operator === "*") {
  7. console.log((num * otherNum).toFixed(2));
  8. } else if (operator === "/") {
  9. console.log((num / otherNum).toFixed(2));
  10. } else if (operator === "%") {
  11. console.log((num % otherNum).toFixed(2));
  12. }
  13. }
  14. calculator(5, "+", 10);
  15. calculator(25.5, "-", 3);
Advertisement
Add Comment
Please, Sign In to add comment