function calculateDecayRate() {
var halfLife = parseFloat(document.getElementById("halfLife").value);
var timeUnits = document.getElementById("timeUnits").value;
var resultDiv = document.getElementById("result");
if (isNaN(halfLife) || halfLife <= 0) {
resultDiv.innerHTML = "Please enter a valid positive number for Half-Life.";
return;
}
// The formula to convert half-life (t_1/2) to decay constant (lambda) is:
// lambda = ln(2) / t_1/2
// where ln(2) is the natural logarithm of 2, approximately 0.693.
var decayRate = Math.log(2) / halfLife; // Using Math.log for natural logarithm
var explanation = "Explanation:";
explanation += "The half-life (t1/2) of a substance is the time it takes for half of the radioactive atoms in a sample to decay.";
explanation += "The decay rate, also known as the decay constant (λ), is a measure of how quickly a radioactive substance decays.";
explanation += "It represents the probability per unit time that a single atom will decay. The relationship between the decay constant and half-life is given by the formula:";
explanation += "λ = ln(2) / t1/2";
explanation += "Where ln(2) is the natural logarithm of 2 (approximately 0.693). A higher decay constant means a shorter half-life and a faster decay rate.";
explanation += "The time units for the decay rate will be the inverse of the units chosen for the half-life (e.g., if half-life is in years, the decay rate will be in per year).";
explanation += "";
var resultHtml = "