JavaScript - 16
JavaScript - 16: Working with Objects & Methods
Create an object called calculator that has three methods: add, subtract, and multiply. Then use the calculator to perform some operations and print the results.
👀 Show Solution
let calculator = {
add: function(a, b) {
return a + b;
},
subtract: function(a, b) {
return a - b;
},
multiply: function(a, b) {
return a * b;
}
};
console.log("Add:", calculator.add(15, 7));
console.log("Subtract:", calculator.subtract(20, 8));
console.log("Multiply:", calculator.multiply(6, 4));