From 4ee1332e8b52fe48f44d24143ace8619d61873ad Mon Sep 17 00:00:00 2001 From: anijit18 Date: Sat, 27 Jul 2024 11:53:30 +0530 Subject: [PATCH] Added geometric progression calculator --- Geometric Progression Calculator/index.html | 42 +++++++++++++ .../manifest.json | 12 ++++ Geometric Progression Calculator/script.js | 38 ++++++++++++ Geometric Progression Calculator/style.css | 61 +++++++++++++++++++ index.html | 42 +++++++++++++ script.js | 38 ++++++++++++ style.css | 61 +++++++++++++++++++ 7 files changed, 294 insertions(+) create mode 100644 Geometric Progression Calculator/index.html create mode 100644 Geometric Progression Calculator/manifest.json create mode 100644 Geometric Progression Calculator/script.js create mode 100644 Geometric Progression Calculator/style.css create mode 100644 index.html create mode 100644 script.js create mode 100644 style.css diff --git a/Geometric Progression Calculator/index.html b/Geometric Progression Calculator/index.html new file mode 100644 index 00000000..47fa1101 --- /dev/null +++ b/Geometric Progression Calculator/index.html @@ -0,0 +1,42 @@ + + + + + + + Geometric Progression + + + +
+
+
+
+ Geometric Progression Calculator +
+ + + + + + + + + + + + + + +

+
+
+
+ + + + + \ No newline at end of file diff --git a/Geometric Progression Calculator/manifest.json b/Geometric Progression Calculator/manifest.json new file mode 100644 index 00000000..bc0c2733 --- /dev/null +++ b/Geometric Progression Calculator/manifest.json @@ -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" + ] + } \ No newline at end of file diff --git a/Geometric Progression Calculator/script.js b/Geometric Progression Calculator/script.js new file mode 100644 index 00000000..a828086c --- /dev/null +++ b/Geometric Progression Calculator/script.js @@ -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)) ) }`; + } +} \ No newline at end of file diff --git a/Geometric Progression Calculator/style.css b/Geometric Progression Calculator/style.css new file mode 100644 index 00000000..3a0edfda --- /dev/null +++ b/Geometric Progression Calculator/style.css @@ -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; +} \ No newline at end of file diff --git a/index.html b/index.html new file mode 100644 index 00000000..47fa1101 --- /dev/null +++ b/index.html @@ -0,0 +1,42 @@ + + + + + + + Geometric Progression + + + +
+
+
+
+ Geometric Progression Calculator +
+ + + + + + + + + + + + + + +

+
+
+
+ + + + + \ No newline at end of file diff --git a/script.js b/script.js new file mode 100644 index 00000000..a828086c --- /dev/null +++ b/script.js @@ -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)) ) }`; + } +} \ No newline at end of file diff --git a/style.css b/style.css new file mode 100644 index 00000000..3a0edfda --- /dev/null +++ b/style.css @@ -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; +} \ No newline at end of file