Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function calculator(num, operator, otherNum) {
- if (operator === "+") {
- console.log((num + otherNum).toFixed(2));
- } else if (operator === "-") {
- console.log((num - otherNum).toFixed(2));
- } else if (operator === "*") {
- console.log((num * otherNum).toFixed(2));
- } else if (operator === "/") {
- console.log((num / otherNum).toFixed(2));
- } else if (operator === "%") {
- console.log((num % otherNum).toFixed(2));
- }
- }
- calculator(5, "+", 10);
- calculator(25.5, "-", 3);
Advertisement
Add Comment
Please, Sign In to add comment