Enter three fractions and select an operation to calculate the result.
Add (+)
Subtract (-)
Multiply (*)
Divide (/)
Result:
function gcd(a, b) {
a = Math.abs(a);
b = Math.abs(b);
while (b) {
var temp = b;
b = a % b;
a = temp;
}
return a;
}
function simplifyFraction(numerator, denominator) {
if (denominator === 0) {
return [numerator, 0]; // Indicate invalid fraction or undefined result
}
if (numerator === 0) {
return [0, 1]; // 0/X is always 0/1
}
var commonDivisor = gcd(numerator, denominator);
var simplifiedNumerator = numerator / commonDivisor;
var simplifiedDenominator = denominator / commonDivisor;
// Ensure denominator is positive
if (simplifiedDenominator < 0) {
simplifiedNumerator *= -1;
simplifiedDenominator *= -1;
}
return [simplifiedNumerator, simplifiedDenominator];
}
function addFractions(n1, d1, n2, d2) {
var commonDenominator = d1 * d2;
var newNumerator1 = n1 * d2;
var newNumerator2 = n2 * d1;
return simplifyFraction(newNumerator1 + newNumerator2, commonDenominator);
}
function subtractFractions(n1, d1, n2, d2) {
var commonDenominator = d1 * d2;
var newNumerator1 = n1 * d2;
var newNumerator2 = n2 * d1;
return simplifyFraction(newNumerator1 – newNumerator2, commonDenominator);
}
function multiplyFractions(n1, d1, n2, d2) {
return simplifyFraction(n1 * n2, d1 * d2);
}
function divideFractions(n1, d1, n2, d2) {
if (n2 === 0) {
return [NaN, NaN]; // Division by zero is undefined
}
return simplifyFraction(n1 * d2, d1 * n2);
}
function calculateFractions() {
var num1 = parseFloat(document.getElementById("numerator1").value);
var den1 = parseFloat(document.getElementById("denominator1").value);
var num2 = parseFloat(document.getElementById("numerator2").value);
var den2 = parseFloat(document.getElementById("denominator2").value);
var num3 = parseFloat(document.getElementById("numerator3").value);
var den3 = parseFloat(document.getElementById("denominator3").value);
var operation = document.getElementById("operation").value;
var resultDiv = document.getElementById("result");
resultDiv.innerHTML = ""; // Clear previous result
// Input validation
if (isNaN(num1) || isNaN(den1) || isNaN(num2) || isNaN(den2) || isNaN(num3) || isNaN(den3)) {
resultDiv.innerHTML = "Please enter valid numbers for all numerators and denominators.";
return;
}
if (den1 === 0 || den2 === 0 || den3 === 0) {
resultDiv.innerHTML = "Denominator cannot be zero.";
return;
}
var intermediateResultNum, intermediateResultDen;
var finalResultNum, finalResultDen;
// Step 1: Calculate F1 op F2
switch (operation) {
case "add":
var res1 = addFractions(num1, den1, num2, den2);
intermediateResultNum = res1[0];
intermediateResultDen = res1[1];
break;
case "subtract":
var res1 = subtractFractions(num1, den1, num2, den2);
intermediateResultNum = res1[0];
intermediateResultDen = res1[1];
break;
case "multiply":
var res1 = multiplyFractions(num1, den1, num2, den2);
intermediateResultNum = res1[0];
intermediateResultDen = res1[1];
break;
case "divide":
var res1 = divideFractions(num1, den1, num2, den2);
if (isNaN(res1[0])) { // Check for division by zero in the first step (if F2 numerator is 0)
resultDiv.innerHTML = "Cannot divide by zero (Fraction 2 numerator is zero).";
return;
}
intermediateResultNum = res1[0];
intermediateResultDen = res1[1];
break;
}
// Step 2: Calculate (F1 op F2) op F3
switch (operation) {
case "add":
var finalRes = addFractions(intermediateResultNum, intermediateResultDen, num3, den3);
finalResultNum = finalRes[0];
finalResultDen = finalRes[1];
break;
case "subtract":
var finalRes = subtractFractions(intermediateResultNum, intermediateResultDen, num3, den3);
finalResultNum = finalRes[0];
finalResultDen = finalRes[1];
break;
case "multiply":
var finalRes = multiplyFractions(intermediateResultNum, intermediateResultDen, num3, den3);
finalResultNum = finalRes[0];
finalResultDen = finalRes[1];
break;
case "divide":
var finalRes = divideFractions(intermediateResultNum, intermediateResultDen, num3, den3);
if (isNaN(finalRes[0])) { // Check for division by zero in the second step (if F3 numerator is 0)
resultDiv.innerHTML = "Cannot divide by zero (Fraction 3 numerator is zero).";
return;
}
finalResultNum = finalRes[0];
finalResultDen = finalRes[1];
break;
}
// Display result
if (finalResultDen === 0) {
resultDiv.innerHTML = "Result is undefined (division by zero).";
} else if (finalResultNum === 0) {
resultDiv.innerHTML = "The result is: 0";
} else if (finalResultDen === 1) {
resultDiv.innerHTML = "The result is: " + finalResultNum + "";
} else {
resultDiv.innerHTML = "The result is: " + finalResultNum + " / " + finalResultDen + "";
}
}
.calculator-container {
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
background-color: #f9f9f9;
padding: 20px;
border-radius: 8px;
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
max-width: 500px;
margin: 20px auto;
border: 1px solid #ddd;
}
.calculator-container h2 {
color: #333;
text-align: center;
margin-bottom: 20px;
}
.calculator-container p {
color: #555;
text-align: center;
margin-bottom: 25px;
}
.input-group {
margin-bottom: 15px;
display: flex;
flex-wrap: wrap;
align-items: center;
gap: 10px;
}
.input-group label {
flex: 1 1 150px;
color: #333;
font-weight: bold;
}
.input-group input[type="number"],
.input-group select {
flex: 2 1 150px;
padding: 10px;
border: 1px solid #ccc;
border-radius: 4px;
font-size: 16px;
box-sizing: border-box;
}
.input-group input[type="number"]:focus,
.input-group select:focus {
border-color: #007bff;
outline: none;
box-shadow: 0 0 0 2px rgba(0, 123, 255, 0.25);
}
button {
display: block;
width: 100%;
padding: 12px 20px;
background-color: #007bff;
color: white;
border: none;
border-radius: 4px;
font-size: 18px;
cursor: pointer;
transition: background-color 0.3s ease;
margin-top: 20px;
}
button:hover {
background-color: #0056b3;
}
.result-container {
margin-top: 25px;
padding: 15px;
background-color: #e9f7ff;
border: 1px solid #cce5ff;
border-radius: 4px;
text-align: center;
}
.result-container h3 {
color: #007bff;
margin-top: 0;
margin-bottom: 10px;
}
.result-container p {
font-size: 20px;
font-weight: bold;
color: #333;
margin: 0;
}
.result-container p strong {
color: #28a745;
}
Understanding Fractions and How to Use the 3 Fraction Calculator
Fractions are a fundamental concept in mathematics, representing a part of a whole. They are written as a ratio of two numbers, a numerator (the top number) and a denominator (the bottom number). For example, in the fraction 1/2, '1' is the numerator, and '2' is the denominator, meaning one part out of two equal parts.
Components of a Fraction
Numerator: The number above the line, indicating how many parts of the whole are being considered.
Denominator: The number below the line, indicating the total number of equal parts the whole is divided into. The denominator can never be zero.
Why Use a 3 Fraction Calculator?
Working with multiple fractions, especially when performing operations like addition, subtraction, multiplication, or division, can become complex. This 3 Fraction Calculator simplifies the process by allowing you to input three fractions and choose an operation, providing an instant, simplified result. It's an invaluable tool for students, educators, and anyone needing to quickly solve fraction problems.
How to Add Fractions
To add fractions, they must have a common denominator. If they don't, you need to find the least common multiple (LCM) of the denominators and convert each fraction to an equivalent fraction with that common denominator. Once the denominators are the same, you simply add the numerators and keep the common denominator. Finally, simplify the resulting fraction.
Example: 1/2 + 1/3 + 1/4
Find a common denominator for 2, 3, and 4, which is 12.
Similar to addition, fractions must have a common denominator before subtraction. Find the LCM, convert the fractions, then subtract the numerators. Simplify the final fraction.
Multiplying fractions is straightforward: multiply the numerators together and multiply the denominators together. Then, simplify the resulting fraction.
Example: 1/2 * 1/3 * 1/4
Multiply numerators: 1 * 1 * 1 = 1.
Multiply denominators: 2 * 3 * 4 = 24.
The result is 1/24. (Already simplified)
How to Divide Fractions
To divide fractions, you "keep, change, flip." Keep the first fraction as it is, change the division sign to multiplication, and flip (find the reciprocal of) the second fraction. Then, multiply the fractions as usual. When dividing three fractions, you perform the operation sequentially from left to right.
Example: (1/2) / (1/3) / (1/4)
First, (1/2) / (1/3) = 1/2 * 3/1 = 3/2.
Then, (3/2) / (1/4) = 3/2 * 4/1 = 12/2.
Simplify: 12/2 = 6.
The result is 6.
Simplifying Fractions
A fraction is in its simplest form (or lowest terms) when its numerator and denominator have no common factors other than 1. To simplify a fraction, divide both the numerator and the denominator by their greatest common divisor (GCD).
Example: Simplify 12/18
Find the GCD of 12 and 18, which is 6.
Divide both by 6: 12 ÷ 6 = 2, and 18 ÷ 6 = 3.
The simplified fraction is 2/3.
This calculator handles all these steps for you, ensuring accurate and simplified results for your three-fraction calculations.