Html code for Complex factor calculator online -online calculator
We will try to give you a new code for every day .
Here is a code for Complex Factor Calculator convertor HTML code
<html lang="en">
<head>
<meta charset="UTF-8"></meta>
<meta content="width=device-width, initial-scale=1.0" name="viewport"></meta>
<title>Complex Fractions Calculator</title>
<style>
body {
font-family: Arial, sans-serif;
text-align: center;
margin: 50px;
}
.fraction-input {
margin-bottom: 10px;
}
</style>
</head>
<body>
<h2>Complex Fractions Calculator</h2>
<div id="fractionInputs">
<!-- Initial fraction input fields -->
<div class="fraction-input">
<input class="numerator" placeholder="Enter numerator" type="number" />
<span>/</span>
<input class="denominator" placeholder="Enter denominator" type="number" />
</div>
</div>
<button onclick="addFractionInput()">Add Fraction</button>
<button onclick="calculateComplexFraction()">Calculate</button>
<p id="result"></p>
<script>
function addFractionInput() {
// Create a new set of input fields for a fraction
var fractionInputs = document.getElementById("fractionInputs");
var newFractionInput = document.createElement("div");
newFractionInput.className = "fraction-input";
newFractionInput.innerHTML = `
<input type="number" class="numerator" placeholder="Enter numerator">
<span>/</span>
<input type="number" class="denominator" placeholder="Enter denominator">
`;
fractionInputs.appendChild(newFractionInput);
}
function calculateComplexFraction() {
// Get all the input values
var numerators = document.querySelectorAll(".numerator");
var denominators = document.querySelectorAll(".denominator");
// Check if the input is valid
if (numerators.length < 2) {
document.getElementById("result").innerHTML = "Please enter at least two fractions.";
return;
}
// Calculate the complex fraction
var resultNumerator = 0;
var resultDenominator = 1;
for (var i = 0; i < numerators.length; i++) {
var numerator = parseInt(numerators[i].value) || 0;
var denominator = parseInt(denominators[i].value) || 1;
if (denominator === 0) {
document.getElementById("result").innerHTML = "Denominator cannot be zero.";
return;
}
resultNumerator = resultNumerator * denominator + numerator * resultDenominator;
resultDenominator *= denominator;
}
// Display the result
document.getElementById("result").innerHTML = "Result: " + resultNumerator + "/" + resultDenominator;
}
</script>
</body>
</html>
Comments
Post a Comment