.calculator-container {
font-family: 'Arial', sans-serif;
max-width: 800px;
margin: 20px auto;
padding: 20px;
border: 1px solid #ddd;
border-radius: 8px;
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
display: flex;
flex-wrap: wrap;
gap: 20px;
}
.calculator-inputs {
flex: 2;
min-width: 300px;
}
.calculator-results {
flex: 1;
min-width: 200px;
background-color: #f9f9f9;
padding: 15px;
border-radius: 6px;
}
.input-group {
margin-bottom: 15px;
}
.input-group label {
display: block;
margin-bottom: 5px;
font-weight: bold;
color: #333;
}
.input-group input[type="number"],
.input-group select {
width: calc(100% – 12px);
padding: 8px;
border: 1px solid #ccc;
border-radius: 4px;
box-sizing: border-box;
}
.input-group input[type="number"]:focus,
.input-group select:focus {
border-color: #007bff;
outline: none;
}
button {
background-color: #007bff;
color: white;
padding: 10px 15px;
border: none;
border-radius: 5px;
cursor: pointer;
font-size: 16px;
transition: background-color 0.3s ease;
}
button:hover {
background-color: #0056b3;
}
#result h3 {
margin-top: 0;
color: #333;
}
#output {
margin-top: 10px;
font-weight: bold;
color: #28a745;
}
function calculateArrhenius() {
var k = parseFloat(document.getElementById("rateConstant").value);
var A = parseFloat(document.getElementById("preExponentialFactor").value);
var Ea = parseFloat(document.getElementById("activationEnergy").value);
var R = parseFloat(document.getElementById("gasConstant").value);
var T = parseFloat(document.getElementById("temperature").value);
var calculateWhat = document.getElementById("calculateWhat").value;
var outputDiv = document.getElementById("output");
var resultHtml = "";
// Ensure R is not zero to prevent division by zero
if (R <= 0) {
outputDiv.innerHTML = "Error: The gas constant (R) must be a positive value.";
return;
}
if (calculateWhat === "rateConstant") {
if (isValidNumber(A) && isValidNumber(Ea) && isValidNumber(R) && isValidNumber(T)) {
if (T <= 0) {
outputDiv.innerHTML = "Error: Absolute temperature (T) must be greater than 0 Kelvin.";
return;
}
var exponent = -Ea / (R * T);
var calculatedK = A * Math.exp(exponent);
resultHtml = "Calculated Rate Constant (k): " + calculatedK.toFixed(6);
} else {
resultHtml = "Please provide valid values for Pre-exponential Factor (A), Activation Energy (Ea), Gas Constant (R), and Temperature (T).";
}
} else if (calculateWhat === "preExponentialFactor") {
if (isValidNumber(k) && isValidNumber(Ea) && isValidNumber(R) && isValidNumber(T)) {
if (T <= 0) {
outputDiv.innerHTML = "Error: Absolute temperature (T) must be greater than 0 Kelvin.";
return;
}
if (k <= 0) {
outputDiv.innerHTML = "Error: Rate constant (k) must be a positive value to calculate A.";
return;
}
var exponent = -Ea / (R * T);
var calculatedA = k / Math.exp(exponent);
resultHtml = "Calculated Pre-exponential Factor (A): " + calculatedA.toFixed(6);
} else {
resultHtml = "Please provide valid values for Rate Constant (k), Activation Energy (Ea), Gas Constant (R), and Temperature (T).";
}
} else if (calculateWhat === "activationEnergy") {
if (isValidNumber(k) && isValidNumber(A) && isValidNumber(R) && isValidNumber(T)) {
if (T <= 0) {
outputDiv.innerHTML = "Error: Absolute temperature (T) must be greater than 0 Kelvin.";
return;
}
if (k <= 0 || A <= 0) {
outputDiv.innerHTML = "Error: Rate constant (k) and Pre-exponential Factor (A) must be positive values to calculate Ea.";
return;
}
var term = k / A;
if (term <= 0) {
outputDiv.innerHTML = "Error: The ratio k/A must be positive to calculate Ea.";
return;
}
var exponent = Math.log(term);
var calculatedEa = -exponent * R * T;
resultHtml = "Calculated Activation Energy (Ea): " + calculatedEa.toFixed(2) + " J/mol";
} else {
resultHtml = "Please provide valid values for Rate Constant (k), Pre-exponential Factor (A), Gas Constant (R), and Temperature (T).";
}
} else if (calculateWhat === "temperature") {
if (isValidNumber(k) && isValidNumber(A) && isValidNumber(Ea) && isValidNumber(R)) {
if (k <= 0 || A <= 0) {
outputDiv.innerHTML = "Error: Rate constant (k) and Pre-exponential Factor (A) must be positive values to calculate T.";
return;
}
var term = k / A;
if (term <= 0) {
outputDiv.innerHTML = "Error: The ratio k/A must be positive to calculate T.";
return;
}
var exponent = Math.log(term);
var calculatedT = (-Ea) / (R * exponent);
if (calculatedT <= 0) {
outputDiv.innerHTML = "Error: Calculated Temperature (T) is not a valid positive absolute temperature.";
return;
}
resultHtml = "Calculated Temperature (T): " + calculatedT.toFixed(2) + " K";
} else {
resultHtml = "Please provide valid values for Rate Constant (k), Pre-exponential Factor (A), Activation Energy (Ea), and Gas Constant (R).";
}
}
outputDiv.innerHTML = resultHtml;
}
function isValidNumber(value) {
return typeof value === 'number' && !isNaN(value) && isFinite(value);
}