From a744271f581d5ce6f560fc38599aefef53504e9e Mon Sep 17 00:00:00 2001 From: Atharv Verma <146646273+Atharvverma1234@users.noreply.github.com> Date: Mon, 16 Dec 2024 09:48:54 +0530 Subject: [PATCH] Added Half-Life Calculator (#1912) --- Calculators/Half-Life-Calculator/README.md | 34 +++++++++ Calculators/Half-Life-Calculator/index.html | 41 +++++++++++ Calculators/Half-Life-Calculator/script.js | 19 +++++ Calculators/Half-Life-Calculator/style.css | 82 +++++++++++++++++++++ index.html | 14 ++++ 5 files changed, 190 insertions(+) create mode 100644 Calculators/Half-Life-Calculator/README.md create mode 100644 Calculators/Half-Life-Calculator/index.html create mode 100644 Calculators/Half-Life-Calculator/script.js create mode 100644 Calculators/Half-Life-Calculator/style.css diff --git a/Calculators/Half-Life-Calculator/README.md b/Calculators/Half-Life-Calculator/README.md new file mode 100644 index 000000000..99decba73 --- /dev/null +++ b/Calculators/Half-Life-Calculator/README.md @@ -0,0 +1,34 @@ +#

Half-Life Calculator

+ +## Description :- + +The Half-Life Calculator is a simple yet visually appealing web application designed to calculate the half-life of a substance based on user inputs. +The Half-Life Calculator is built with HTML, CSS, and JavaScript, offering users a seamless way to compute the half-life of substances using the formula: + +$$ +T_{1/2} = \frac{t \cdot \ln(2)}{\ln\left(\frac{N_0}{N}\right)} +$$ + +Where: +- **T1/2** = Half-life of the substance +- **t** = Elapsed time +- **N0** = Initial amount of the substance +- **N** = Remaining amount of the substance + + +## Tech Stacks :- + +- HTML +- CSS +- JavaScript + +## Features :- + +- Simple and minimalistic design for effortless input and navigation. +- Displays results rounded to two decimal places for clarity. +- Smoothly transitioning gradient colors that create an engaging visual effect. +- Validates inputs to ensure only positive numerical values are accepted. + +## Screenshots :- + +![image](https://github.com/user-attachments/assets/755a3ccb-7b59-416f-8795-bd9b4eae67ac) diff --git a/Calculators/Half-Life-Calculator/index.html b/Calculators/Half-Life-Calculator/index.html new file mode 100644 index 000000000..01e155670 --- /dev/null +++ b/Calculators/Half-Life-Calculator/index.html @@ -0,0 +1,41 @@ + + + + + + + Half-Life Calculator + + +
+ +

Half-Life Calculator

+ + +
+ + +
+ + +
+ + +
+ + +
+ + +
+ + + + + +
+
+ + + + \ No newline at end of file diff --git a/Calculators/Half-Life-Calculator/script.js b/Calculators/Half-Life-Calculator/script.js new file mode 100644 index 000000000..faa77cc24 --- /dev/null +++ b/Calculators/Half-Life-Calculator/script.js @@ -0,0 +1,19 @@ +function calculateHalfLife() { + // Get user input values from the form fields + const initialAmount = parseFloat(document.getElementById('initial-amount').value); + const remainingAmount = parseFloat(document.getElementById('remaining-amount').value); + const time = parseFloat(document.getElementById('time').value); + + // Check if all inputs are valid numbers + if (isNaN(initialAmount) || isNaN(remainingAmount) || isNaN(time) || initialAmount <= 0 || remainingAmount <= 0 || time <= 0) { + document.getElementById('result').textContent = "Please enter valid positive numbers."; + return; + } + + // Calculate the half-life using the formula: + // T(1/2) = (t * ln(2)) / ln(N0 / N) + const halfLife = (time * Math.log(2)) / Math.log(initialAmount / remainingAmount); + + // Display the calculated half-life with two decimal places + document.getElementById('result').textContent = `The half-life is approximately ${halfLife.toFixed(2)} units of time.`; +} \ No newline at end of file diff --git a/Calculators/Half-Life-Calculator/style.css b/Calculators/Half-Life-Calculator/style.css new file mode 100644 index 000000000..3ef947d1e --- /dev/null +++ b/Calculators/Half-Life-Calculator/style.css @@ -0,0 +1,82 @@ +body { + font-family: 'Arial', sans-serif; + margin: 0; + padding: 0; + display: flex; + justify-content: center; + align-items: center; + height: 100vh; + background: linear-gradient(270deg, hsl(269, 98%, 49%), #2575fc); + background-size: 800% 800%; + color: #fff; + animation: color-transition 6s infinite; +} + +@keyframes color-transition { + 0% { + background-position: 0% 50%; + } + 50% { + background-position: 100% 50%; + } + 100% { + background-position: 0% 50%; + } +} + +.calculator { + background: rgba(255, 255, 255, 0.1); + backdrop-filter: blur(10px); + padding: 20px 30px; + border-radius: 15px; + box-shadow: 0 10px 25px rgba(0, 0, 0, 0.2); + text-align: center; + width: 300px; +} + + +.calculator h1 { + font-size: 32px; + margin-bottom: 27px; +} + +.input-group { + margin-bottom: 25px; + margin-right: 18px; +} + +.input-group label { + display: block; + font-size: 18px; + margin-bottom: 5px; +} + +.input-group input { + width: 100%; + padding: 10px; + border: none; + border-radius: 5px; + font-size: 16px; +} + +button { + background: #ff7eb3; + margin-top: 10px; + margin-bottom: 10px; + border: none; + color: #fff; + padding: 10px 15px; + font-size: 18px; + border-radius: 5px; + cursor: pointer; + transition: background 0.3s; +} + +button:hover { + background: #ff4e8a; +} + +.result { + margin-top: 25px; + font-size: 18px; +} \ No newline at end of file diff --git a/index.html b/index.html index 7386ead22..d12d678c4 100644 --- a/index.html +++ b/index.html @@ -2675,6 +2675,20 @@

Calculates a Hailstone series by repeatedly dividing by 2 if even or multipl +
+
+

Half-Life Calculator

+

Calculates half-life of a substance based on user inputs.

+ +
+

Happy Number Calculator