-
Notifications
You must be signed in to change notification settings - Fork 183
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added geometric progression calculator
- Loading branch information
Showing
7 changed files
with
294 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,42 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css"> | ||
<title>Geometric Progression</title> | ||
<link rel="stylesheet" href="style.css"> | ||
</head> | ||
<body style="background-color: #FFF2D7;"> | ||
<div class="container" style="width: 500px; padding: 25px; background-color:#F98866; border: rgb(3, 3, 3); border-radius: 23px; position: relative; top: 80px;"> | ||
<div class="row justify-content-center"> | ||
<div class="col-md-12"> | ||
<header style="font-size:20px; border-radius:20px; margin-bottom:20px"> | ||
Geometric Progression Calculator | ||
</header> | ||
<label for="firstTerm">First Term (a₁):</label> | ||
<input type="number" id="firstTerm" required> | ||
|
||
<label for="commonRatio">Common Ratio (r):</label> | ||
<input type="number" id="commonRatio" required> | ||
|
||
<label for="termNumber">Term Number (n):</label> | ||
<input type="number" id="termNumber" required> | ||
|
||
<label for="calculationType">Choose Calculation:</label> | ||
<select id="calculationType"> | ||
<option value="nthTerm">Nth Term</option> | ||
<option value="sumOfTerms">Sum of First N Terms</option> | ||
</select> | ||
|
||
<button onclick="calculate()">Calculate</button> | ||
|
||
<p id="result"></p> | ||
</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,12 @@ | ||
{ | ||
"manifest_version": 3, | ||
"name": "Geometric Progression Calculator", | ||
"version": "1.0", | ||
"description": "A tool that finds us the nth term and sum of n terms of the given Geometric Progression", | ||
"action": { | ||
"default_popup": "index.html" | ||
}, | ||
"permissions": [ | ||
"storage" | ||
] | ||
} |
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,38 @@ | ||
function calculate() { | ||
// Get input values | ||
const firstTerm = parseFloat(document.getElementById('firstTerm').value); | ||
const commonRatio = parseFloat(document.getElementById('commonRatio').value); | ||
const termNumber = parseInt(document.getElementById('termNumber').value); | ||
const calculationType = document.getElementById('calculationType').value; | ||
|
||
// Perform the selected calculation | ||
let result; | ||
if (calculationType === 'nthTerm') { | ||
// Calculate the nth term | ||
result = calculateNthTerm(firstTerm, commonRatio, termNumber); | ||
} else if (calculationType === 'sumOfTerms') { | ||
// Calculate the sum of the first n terms | ||
result = calculateSumOfTerms(firstTerm, commonRatio, termNumber); | ||
} | ||
|
||
// Display the result | ||
const resultElement = document.getElementById('result'); | ||
resultElement.textContent = result; | ||
} | ||
|
||
function calculateNthTerm(firstTerm, commonRatio, termNumber) { | ||
// Calculate the nth term | ||
return `The ${termNumber}th term is: ${firstTerm*Math.pow(commonRatio,(termNumber-1))}`; | ||
} | ||
|
||
function calculateSumOfTerms(firstTerm, commonRatio, termNumber) { | ||
// Calculate the sum of the first n terms | ||
if(commonRatio == 1) | ||
{ | ||
return `The sum of the first ${termNumber} terms is: ${ (firstTerm*termNumber) }`; | ||
} | ||
else | ||
{ | ||
return `The sum of the first ${termNumber} terms is: ${ ( (firstTerm*(1-Math.pow(commonRatio,termNumber))/(1-commonRatio)) ) }`; | ||
} | ||
} |
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,61 @@ | ||
body { | ||
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; | ||
margin: 0; | ||
padding: 0; | ||
background-color: #f4f4f4; | ||
} | ||
|
||
header { | ||
background-color: #226b80; | ||
color: #fff; | ||
text-align: center; | ||
padding: 1em; | ||
} | ||
|
||
#calculator { | ||
max-width: 300px; | ||
margin: 20px auto; | ||
border: 1px solid #ccc; | ||
padding: 20px; | ||
border-radius: 8px; | ||
background: linear-gradient(to right, #00fff0, #3d6cb9); | ||
background-color: #fff; | ||
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1); | ||
} | ||
|
||
label { | ||
display: block; | ||
margin-bottom: 8px; | ||
color: #333; | ||
} | ||
|
||
input, | ||
select { | ||
width: 100%; | ||
padding: 10px; | ||
margin-bottom: 16px; | ||
box-sizing: border-box; | ||
border-radius: 9px; | ||
} | ||
|
||
button { | ||
width: 100%; | ||
height: 40px; | ||
font-size: 16px; | ||
cursor: pointer; | ||
background-color: #28f2fc; | ||
color: #fff; | ||
border: none; | ||
border-radius: 9px; | ||
transition: background-color 0.3s; | ||
} | ||
|
||
button:hover { | ||
background-color: #45a09e; | ||
} | ||
|
||
#result { | ||
margin-top: 16px; | ||
font-weight: bold; | ||
color: #333; | ||
} |
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,42 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css"> | ||
<title>Geometric Progression</title> | ||
<link rel="stylesheet" href="style.css"> | ||
</head> | ||
<body style="background-color: #FFF2D7;"> | ||
<div class="container" style="width: 500px; padding: 25px; background-color:#F98866; border: rgb(3, 3, 3); border-radius: 23px; position: relative; top: 80px;"> | ||
<div class="row justify-content-center"> | ||
<div class="col-md-12"> | ||
<header style="font-size:20px; border-radius:20px; margin-bottom:20px"> | ||
Geometric Progression Calculator | ||
</header> | ||
<label for="firstTerm">First Term (a₁):</label> | ||
<input type="number" id="firstTerm" required> | ||
|
||
<label for="commonRatio">Common Ratio (r):</label> | ||
<input type="number" id="commonRatio" required> | ||
|
||
<label for="termNumber">Term Number (n):</label> | ||
<input type="number" id="termNumber" required> | ||
|
||
<label for="calculationType">Choose Calculation:</label> | ||
<select id="calculationType"> | ||
<option value="nthTerm">Nth Term</option> | ||
<option value="sumOfTerms">Sum of First N Terms</option> | ||
</select> | ||
|
||
<button onclick="calculate()">Calculate</button> | ||
|
||
<p id="result"></p> | ||
</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,38 @@ | ||
function calculate() { | ||
// Get input values | ||
const firstTerm = parseFloat(document.getElementById('firstTerm').value); | ||
const commonRatio = parseFloat(document.getElementById('commonRatio').value); | ||
const termNumber = parseInt(document.getElementById('termNumber').value); | ||
const calculationType = document.getElementById('calculationType').value; | ||
|
||
// Perform the selected calculation | ||
let result; | ||
if (calculationType === 'nthTerm') { | ||
// Calculate the nth term | ||
result = calculateNthTerm(firstTerm, commonRatio, termNumber); | ||
} else if (calculationType === 'sumOfTerms') { | ||
// Calculate the sum of the first n terms | ||
result = calculateSumOfTerms(firstTerm, commonRatio, termNumber); | ||
} | ||
|
||
// Display the result | ||
const resultElement = document.getElementById('result'); | ||
resultElement.textContent = result; | ||
} | ||
|
||
function calculateNthTerm(firstTerm, commonRatio, termNumber) { | ||
// Calculate the nth term | ||
return `The ${termNumber}th term is: ${firstTerm*Math.pow(commonRatio,(termNumber-1))}`; | ||
} | ||
|
||
function calculateSumOfTerms(firstTerm, commonRatio, termNumber) { | ||
// Calculate the sum of the first n terms | ||
if(commonRatio == 1) | ||
{ | ||
return `The sum of the first ${termNumber} terms is: ${ (firstTerm*termNumber) }`; | ||
} | ||
else | ||
{ | ||
return `The sum of the first ${termNumber} terms is: ${ ( (firstTerm*(1-Math.pow(commonRatio,termNumber))/(1-commonRatio)) ) }`; | ||
} | ||
} |
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,61 @@ | ||
body { | ||
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; | ||
margin: 0; | ||
padding: 0; | ||
background-color: #f4f4f4; | ||
} | ||
|
||
header { | ||
background-color: #226b80; | ||
color: #fff; | ||
text-align: center; | ||
padding: 1em; | ||
} | ||
|
||
#calculator { | ||
max-width: 300px; | ||
margin: 20px auto; | ||
border: 1px solid #ccc; | ||
padding: 20px; | ||
border-radius: 8px; | ||
background: linear-gradient(to right, #00fff0, #3d6cb9); | ||
background-color: #fff; | ||
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1); | ||
} | ||
|
||
label { | ||
display: block; | ||
margin-bottom: 8px; | ||
color: #333; | ||
} | ||
|
||
input, | ||
select { | ||
width: 100%; | ||
padding: 10px; | ||
margin-bottom: 16px; | ||
box-sizing: border-box; | ||
border-radius: 9px; | ||
} | ||
|
||
button { | ||
width: 100%; | ||
height: 40px; | ||
font-size: 16px; | ||
cursor: pointer; | ||
background-color: #28f2fc; | ||
color: #fff; | ||
border: none; | ||
border-radius: 9px; | ||
transition: background-color 0.3s; | ||
} | ||
|
||
button:hover { | ||
background-color: #45a09e; | ||
} | ||
|
||
#result { | ||
margin-top: 16px; | ||
font-weight: bold; | ||
color: #333; | ||
} |