Calculate basic and advanced math operations using our easy-to-use free online calculator.
Add
Subtract
Multiply
Divide
function calculate(){
const num1 = parseFloat(document.getElementById(“inputNumber1”).value);
const num2 = parseFloat(document.getElementById(“inputNumber2”).value);
const operation = document.getElementById(“operation”).value;
let result = 0;
if (isNaN(num1) || isNaN(num2)) {
alert(“Please enter valid numbers for both fields.”);
return;
}
switch (operation) {
case ‘add’:
result = num1 + num2;
break;
case ‘subtract’:
result = num1 – num2;
break;
case ‘multiply’:
result = num1 * num2;
break;
case ‘divide’:
if (num2 === 0) {
alert(“Cannot divide by zero.”);
return;
}
result = num1 / num2;
break;
}
document.getElementById(“result”).value = result.toFixed(2);
}
function resetCalculator(){
document.querySelectorAll(“#calculator input”).forEach(el=>el.value=””);
document.getElementById(“operation”).value=”add”;
}
This easy-to-use free online calculator helps you perform basic math calculations quickly. Whether you’re adding, subtracting, multiplying, or dividing, this tool will give you the answer you need.
How It Works
Simply input two numbers and select the operation you’d like to perform (addition, subtraction, multiplication, or division). The result will appear in the result box.
Why Use This Calculator?
It’s simple, efficient, and can be used anytime you need to perform quick calculations without needing to open a calculator app or use a physical calculator.