HTML code for Common Factor Calculators -free html code for common factor calculators
We will try to give you a new code for every day .
Here is a code for Common 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>Common Factors Calculator</title>
<style>
body {
font-family: Arial, sans-serif;
text-align: center;
margin: 50px;
}
</style>
</head>
<body>
<h2>Common Factors Calculator</h2>
<label for="numbers">Enter Numbers (comma-separated):</label>
<input id="numbers" placeholder="Enter numbers" type="text" />
<br />
<button onclick="calculateCommonFactors()">Calculate Common Factors</button>
<p id="result"></p>
<script>
function calculateCommonFactors() {
// Get the input values as an array of numbers
var inputNumbers = document.getElementById("numbers").value.split(',');
// Convert the input strings to numbers
var numbers = inputNumbers.map(function(num) {
return parseInt(num.trim());
});
// Check if the input is valid
if (numbers.some(isNaN)) {
document.getElementById("result").innerHTML = "Please enter valid numbers.";
return;
}
// Find the common factors
var commonFactors = findCommonFactors(numbers);
// Display the result
document.getElementById("result").innerHTML = "Common Factors: " + commonFactors.join(", ");
}
function findCommonFactors(numbers) {
// Find factors of each number
var factorsArray = numbers.map(findFactors);
// Find the common factors
var commonFactors = factorsArray.reduce(function (accumulator, factors) {
return accumulator.filter(value => factors.includes(value));
});
return commonFactors;
}
function findFactors(number) {
// Find factors of a number
var factors = [];
for (var i = 1; i <= Math.abs(number); i++) {
if (number % i === 0) {
factors.push(i);
}
}
return factors;
}
</script>
</body>
</html>
Comments
Post a Comment