.simplest-form-container {
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
max-width: 800px;
margin: 20px auto;
padding: 25px;
border: 1px solid #e1e1e1;
border-radius: 12px;
background-color: #ffffff;
box-shadow: 0 4px 6px rgba(0,0,0,0.05);
}
.sf-header {
text-align: center;
margin-bottom: 30px;
}
.sf-header h2 {
color: #2c3e50;
margin-bottom: 10px;
}
.sf-input-group {
display: flex;
flex-direction: column;
align-items: center;
gap: 15px;
margin-bottom: 25px;
}
.fraction-input-box {
display: flex;
flex-direction: column;
align-items: center;
}
.fraction-input-box input {
width: 120px;
padding: 12px;
font-size: 1.2rem;
text-align: center;
border: 2px solid #3498db;
border-radius: 8px;
outline: none;
}
.fraction-line {
width: 140px;
height: 3px;
background-color: #2c3e50;
margin: 10px 0;
}
.sf-button {
background-color: #3498db;
color: white;
padding: 15px 40px;
border: none;
border-radius: 8px;
font-size: 1.1rem;
font-weight: bold;
cursor: pointer;
transition: background 0.3s ease;
}
.sf-button:hover {
background-color: #2980b9;
}
#sf-result-area {
margin-top: 30px;
padding: 20px;
border-radius: 8px;
background-color: #f8f9fa;
display: none;
border-left: 5px solid #3498db;
}
.sf-result-value {
font-size: 1.5rem;
font-weight: bold;
color: #2c3e50;
text-align: center;
margin-top: 15px;
}
.sf-steps {
font-size: 0.95rem;
color: #7f8c8d;
line-height: 1.6;
margin-top: 15px;
}
.article-section {
margin-top: 40px;
line-height: 1.8;
color: #444;
}
.article-section h3 {
color: #2c3e50;
border-bottom: 2px solid #eee;
padding-bottom: 10px;
}
.example-box {
background-color: #eef7fd;
padding: 15px;
border-radius: 6px;
margin: 15px 0;
}
function calculateSimplestForm() {
var num = document.getElementById("sf-numerator").value;
var den = document.getElementById("sf-denominator").value;
var resultArea = document.getElementById("sf-result-area");
var outputText = document.getElementById("sf-output-text");
var resultDisplay = document.getElementById("sf-result-display");
var stepsDisplay = document.getElementById("sf-steps-display");
// Validate inputs
if (num === "" || den === "") {
alert("Please enter both a numerator and a denominator.");
return;
}
var n = parseInt(num);
var d = parseInt(den);
if (d === 0) {
alert("Denominator cannot be zero.");
return;
}
// Euclidean Algorithm for GCD
var findGCD = function(a, b) {
a = Math.abs(a);
b = Math.abs(b);
while (b) {
var t = b;
b = a % b;
a = t;
}
return a;
};
var commonDivisor = findGCD(n, d);
var simpleNum = n / commonDivisor;
var simpleDen = d / commonDivisor;
// Correct sign handling
if (simpleDen < 0) {
simpleNum = -simpleNum;
simpleDen = -simpleDen;
}
// Formatting result
resultArea.style.display = "block";
outputText.innerHTML = "
Result: The fraction " + n + "/" + d + " in its simplest form is:";
if (simpleDen === 1) {
resultDisplay.innerHTML = simpleNum;
} else {
resultDisplay.innerHTML = simpleNum + " / " + simpleDen;
}
// Show steps
var decimalValue = (n / d).toFixed(4);
stepsDisplay.innerHTML = "
Calculation Steps:" +
"1. Found the Greatest Common Divisor (GCD) of " + Math.abs(n) + " and " + Math.abs(d) + ", which is
" + commonDivisor + "." +
"2. Divided the numerator by " + commonDivisor + ": " + n + " ÷ " + commonDivisor + " = " + simpleNum + "." +
"3. Divided the denominator by " + commonDivisor + ": " + d + " ÷ " + commonDivisor + " = " + simpleDen + "." +
"4. Decimal Equivalent:
" + decimalValue + ".";
}