How to use: Enter any 3 values to solve for the unknown (X), or enter all 4 values to check if the ratios are equivalent.
=
What are Equivalent Ratios?
An equivalent ratio compares two quantities that share the same relationship. Mathematically, the ratios A:B and C:D are equivalent if the fraction A/B is equal to C/D. This concept is fundamental in scaling recipes, determining map distances, and calculating unit prices.
The Cross-Multiplication Formula
To determine if two ratios are equivalent, or to solve for a missing value (X), we use the cross-product property:
If A / B = C / D, then A × D = B × C
Real-World Examples
Cooking: A recipe requires 2 cups of flour for every 3 eggs. If you want to use 9 eggs, how much flour do you need? (2/3 = X/9).
Travel Speed: If a car travels 120 miles in 2 hours, the rate is 60 miles per hour. An equivalent rate would be traveling 300 miles in 5 hours.
Pricing: If 4 apples cost $2.00, then 8 apples should cost $4.00 to maintain an equivalent unit rate.
How to Calculate a Unit Rate
A unit rate is a ratio where the second term (denominator) is 1. To find the unit rate of A/B, simply divide A by B. For example, if you run 10 km in 2 hours, your unit rate is 10 ÷ 2 = 5 km/hour.
function calculateRatio() {
// Get input values
var aInput = document.getElementById("val_a").value;
var bInput = document.getElementById("val_b").value;
var cInput = document.getElementById("val_c").value;
var dInput = document.getElementById("val_d").value;
// Parse to float, track which are empty
var a = parseFloat(aInput);
var b = parseFloat(bInput);
var c = parseFloat(cInput);
var d = parseFloat(dInput);
var resultBox = document.getElementById("ratioResult");
resultBox.style.display = "block";
resultBox.innerHTML = ""; // Clear previous results
var inputs = [aInput, bInput, cInput, dInput];
var filledCount = 0;
for(var i=0; i<inputs.length; i++) {
if(inputs[i] !== "") filledCount++;
}
// Logic Branch 1: Validation
if (filledCount < 3) {
resultBox.innerHTML = "Please enter at least 3 values to calculate the missing one.";
return;
}
// Logic Branch 2: Solve for X (Exactly 3 inputs)
if (filledCount === 3) {
var solvedVal = 0;
var calculationHtml = "";
var unitRate = 0;
if (inputs[3] === "") { // Solve for D
if (a === 0) { resultBox.innerHTML = "Cannot divide by zero (A is 0)."; return; }
solvedVal = (b * c) / a;
calculationHtml = `Solving for D:Formula: D = (B × C) / ACalculation: (${b} × ${c}) ÷ ${a} = ${solvedVal}`;
document.getElementById("val_d").value = Number(solvedVal.toFixed(4)); // Auto-fill
unitRate = a / b;
}
else if (inputs[2] === "") { // Solve for C
if (b === 0) { resultBox.innerHTML = "Cannot divide by zero (B is 0)."; return; }
solvedVal = (a * d) / b;
calculationHtml = `Solving for C:Formula: C = (A × D) / BCalculation: (${a} × ${d}) ÷ ${b} = ${solvedVal}`;
document.getElementById("val_c").value = Number(solvedVal.toFixed(4));
unitRate = a / b;
}
else if (inputs[1] === "") { // Solve for B
if (c === 0) { resultBox.innerHTML = "Cannot divide by zero (C is 0)."; return; }
solvedVal = (a * d) / c;
calculationHtml = `Solving for B:Formula: B = (A × D) / CCalculation: (${a} × ${d}) ÷ ${c} = ${solvedVal}`;
document.getElementById("val_b").value = Number(solvedVal.toFixed(4));
unitRate = c / d;
}
else if (inputs[0] === "") { // Solve for A
if (d === 0) { resultBox.innerHTML = "Cannot divide by zero (D is 0)."; return; }
solvedVal = (b * c) / d;
calculationHtml = `Solving for A:Formula: A = (B × C) / DCalculation: (${b} × ${c}) ÷ ${d} = ${solvedVal}`;
document.getElementById("val_a").value = Number(solvedVal.toFixed(4));
unitRate = c / d;
}
// Display Result
resultBox.innerHTML = `
Result: ${Number(solvedVal.toFixed(4))}
${calculationHtml}
Unit Rate: ${Number(unitRate.toFixed(4))} (Value per 1 unit of denominator)
`;
}
// Logic Branch 3: Check Equivalence (4 inputs)
else if (filledCount === 4) {
if (b === 0 || d === 0) {
resultBox.innerHTML = "Denominators (B and D) cannot be zero.";
return;
}
// Cross multiply check
var cross1 = a * d;
var cross2 = b * c;
var tolerance = 0.0000001; // Float precision handling
var isEquivalent = Math.abs(cross1 – cross2) < tolerance;
var statusColor = isEquivalent ? "#27ae60" : "#c0392b";
var statusText = isEquivalent ? "Equivalent!" : "Not Equivalent";
var operator = isEquivalent ? "=" : "≠";
resultBox.innerHTML = `
${statusText}
Cross-Product Check:
${a} × ${d} = ${Number(cross1.toFixed(4))}
${b} × ${c} = ${Number(cross2.toFixed(4))}
Unit Rate Check:
Ratio 1: ${a}/${b} = ${Number((a/b).toFixed(4))}
Ratio 2: ${c}/${d} = ${Number((c/d).toFixed(4))}
Conclusion: ${a}:${b} ${operator} ${c}:${d}