-
Notifications
You must be signed in to change notification settings - Fork 399
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
FEAT #638 - Added Averages Calculator
- Loading branch information
1 parent
ded4fe2
commit 93ec18b
Showing
6 changed files
with
143 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# Averages Calculator | ||
|
||
## Overview | ||
This is a simple web-based averages calculator that allows users to input comma-separated values and calculates the arithmetic, geometric, and harmonic means. | ||
|
||
## Technologies Used | ||
- HTML | ||
- CSS | ||
- JavaScript | ||
|
||
## Features | ||
- Input validation ensures only numerical values are accepted. | ||
- Calculates arithmetic mean, geometric mean, and harmonic mean. | ||
- Clean and responsive user interface. | ||
|
||
## Screenshots | ||
![alt text](./assets/demo.png) |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
<title>Averages Calculator</title> | ||
<link rel="stylesheet" href="style.css" /> | ||
</head> | ||
<body> | ||
<div class="container"> | ||
<h2 class="heading">Averages Calculator</h2> | ||
<hr /> | ||
<div class="input-section"> | ||
<label for="values-input">Enter comma-separated values:</label> | ||
<textarea id="values-input" rows="4"></textarea> | ||
</div> | ||
<button id="calculate-btn">Calculate Averages</button> | ||
<div class="results"> | ||
<h3>Results</h3> | ||
<div class="result"> | ||
<span>Arithmetic Mean:</span> | ||
<span id="arithmetic-mean">-</span> | ||
</div> | ||
<div class="result"> | ||
<span>Geometric Mean:</span> | ||
<span id="geometric-mean">-</span> | ||
</div> | ||
<div class="result"> | ||
<span>Harmonic Mean:</span> | ||
<span id="harmonic-mean">-</span> | ||
</div> | ||
</div> | ||
</div> | ||
<script src="script.js"></script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
document.getElementById("calculate-btn").addEventListener("click", function () { | ||
const valuesInput = document.getElementById("values-input").value; | ||
const numbers = valuesInput.split(",").map((num) => parseFloat(num.trim())); | ||
|
||
const arithmeticMean = | ||
numbers.reduce((sum, num) => sum + num, 0) / numbers.length; | ||
|
||
let geometricMean = 1; | ||
for (const num of numbers) { | ||
geometricMean *= num; | ||
} | ||
geometricMean = Math.pow(geometricMean, 1 / numbers.length); | ||
|
||
const harmonicMean = | ||
numbers.length / numbers.reduce((sum, num) => sum + 1 / num, 0); | ||
|
||
document.getElementById("arithmetic-mean").textContent = | ||
arithmeticMean.toFixed(2); | ||
document.getElementById("geometric-mean").textContent = | ||
geometricMean.toFixed(2); | ||
document.getElementById("harmonic-mean").textContent = | ||
harmonicMean.toFixed(2); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
body { | ||
font-family: Arial, sans-serif; | ||
} | ||
|
||
.container { | ||
max-width: 600px; | ||
margin: 0 auto; | ||
padding: 20px; | ||
} | ||
|
||
.heading { | ||
text-align: center; | ||
} | ||
|
||
.input-section { | ||
margin-bottom: 20px; | ||
} | ||
|
||
input[type="text"], | ||
textarea { | ||
width: 100%; | ||
padding: 8px; | ||
margin-top: 5px; | ||
margin-bottom: 10px; | ||
box-sizing: border-box; | ||
} | ||
|
||
button { | ||
display: block; | ||
width: 100%; | ||
padding: 10px; | ||
background-color: #007bff; | ||
color: white; | ||
border: none; | ||
cursor: pointer; | ||
} | ||
|
||
button:hover { | ||
background-color: #0056b3; | ||
} | ||
|
||
.results { | ||
margin-top: 20px; | ||
} | ||
|
||
.result { | ||
margin-bottom: 10px; | ||
} | ||
|
||
.result span { | ||
display: inline-block; | ||
width: 150px; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters