Quickly calculate any type of math with our free online calculator tool.
Add
Subtract
Multiply
Divide
function calculate() {
let num1 = parseFloat(document.getElementById(“number1”).value);
let num2 = parseFloat(document.getElementById(“number2”).value);
let operation = document.getElementById(“operation”).value;
let result;
if (isNaN(num1) || isNaN(num2)) {
alert(“Please enter valid numbers.”);
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;
default:
result = 0;
}
document.getElementById(“result”).value = result.toFixed(2);
}
function resetCalculator() {
document.querySelectorAll(“#calculator input”).forEach(el => el.value = “”);
document.getElementById(“result”).value = “”;
}
This free online calculator allows you to perform basic math operations instantly. Whether you need to add, subtract, multiply, or divide, this tool is designed to handle all of your calculations with ease.
Enter the numbers in the input fields and select the operation you wish to perform. Press “Calculate” to see the result. You can also reset the fields if needed.