Hello Friends Today, through this tutorial, I will tell you How to Create XNOR Calculator Using JavaScript with HTML? Below is an example of an XNOR calculator using HTML and JavaScript. This example assumes that you want to calculate the XNOR (equivalence) of two binary values.
index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>XNOR Calculator</title>
<style>
body {
font-family: Arial, sans-serif;
margin: 20px;
}
label {
display: block;
margin-bottom: 8px;
}
input {
width: 100%;
padding: 8px;
margin-bottom: 16px;
box-sizing: border-box;
}
button {
background-color: #4CAF50;
color: white;
padding: 10px 15px;
border: none;
border-radius: 4px;
cursor: pointer;
}
button:hover {
background-color: #45a049;
}
p {
margin-top: 16px;
}
</style>
</head>
<body>
<h2>XNOR Calculator</h2>
<label for="input1">Enter Binary Value 1:</label>
<input type="text" id="input1" placeholder="Enter binary value 1">
<label for="input2">Enter Binary Value 2:</label>
<input type="text" id="input2" placeholder="Enter binary value 2">
<button onclick="calculateXNOR()">Calculate XNOR</button>
<p id="result"></p>
<script>
function calculateXNOR() {
// Get the binary input values
const binary1 = document.getElementById('input1').value;
const binary2 = document.getElementById('input2').value;
// Validate inputs to ensure they are binary strings
if (!/^[01]+$/.test(binary1) || !/^[01]+$/.test(binary2)) {
alert('Please enter valid binary values (0s and 1s only).');
return;
}
// Convert binary strings to integers
const number1 = parseInt(binary1, 2);
const number2 = parseInt(binary2, 2);
// Calculate XNOR (equivalence)
const result = number1 === number2;
// Display the result
document.getElementById('result').innerHTML = `XNOR Result: ${result}`;
}
</script>
</body>
</html>
This HTML file includes two input fields for entering binary values, a button to trigger the XNOR calculation, and a result paragraph to display the calculated XNOR result. The `calculateXNOR` function converts the binary strings to integers, performs the XNOR operation, and displays the result on the page.