Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Discriminant Calculator #1748

Merged
merged 6 commits into from
Aug 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions Calculators/Discriminant-Calculator/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# <p align="center">Discriminant Calculator</p>

## Description :-

Calculates the discriminant of a quadratic equation.

## Tech Stacks :-

- HTML
- CSS
- JavaScript

## Screenshots :-

![image](https://github.com/user-attachments/assets/e88cb389-9de1-496b-8f40-6ce999d36a3c)
32 changes: 32 additions & 0 deletions Calculators/Discriminant-Calculator/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<!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="./style.css">
<title>Discriminant Calculator</title>
</head>

<body>
<div class="container">
<h1>DISCRIMINANT CALCULATOR</h1>

<p>Please enter the coefficients <strong>a</strong>, <strong>b</strong> and <strong>c</strong> of a quadratic
equation of the form:<br><strong id="equation">ax&#x00B2; + bx + c = 0</strong></p>

<form name="input_form" action="javascript:validate();">
<span>a = <input type="text" name="aterm" size="5" required></span>
<span> b = <input type="text" name="bterm" size="5" required></span>
<span> c = <input type="text" name="cterm" size="5" required></span>
<div><button type="submit" value="Calculate"> Calculate Discriminant </button></div>
</form>

<p id="output_text" />
<p id="outputValue" />

<script src="./script.js"></script>
</div>
</body>

</html>
34 changes: 34 additions & 0 deletions Calculators/Discriminant-Calculator/script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
'use strict'

function validate() {
// Get the input values
var a = parseFloat(document.forms["input_form"]["aterm"].value);
var b = parseFloat(document.forms["input_form"]["bterm"].value);
var c = parseFloat(document.forms["input_form"]["cterm"].value);

var outputText, outputValue;

// Validate the inputs
if (isNaN(a) || isNaN(b) || isNaN(c)) {
outputText = "All coefficients must be numbers!";
} else if (a === 0) {
outputText = "<em>a</em> cannot be zero!";
} else {
// Calculate the discriminant
var discriminant = Math.pow(b, 2) - 4 * a * c;

outputText = "For the equation <strong>" + (a === 1 ? "" : a) + "x\u00B2 + " + (b === 1 ? "" : b) + "x + " + c + " = 0</strong>,";

if (discriminant > 0) {
outputValue = "The discriminant (D) is <strong>" + discriminant + "</strong>. There are two distinct real roots.";
} else if (discriminant === 0) {
outputValue = "The discriminant (D) is <strong>" + discriminant + "</strong>. There is exactly one real root.";
} else {
outputValue = "The discriminant (D) is <strong>" + discriminant + "</strong>. There are no real roots (complex roots).";
}
}

// Output the result
document.getElementById("output_text").innerHTML = outputText;
document.getElementById("outputValue").innerHTML = outputValue;
}
101 changes: 101 additions & 0 deletions Calculators/Discriminant-Calculator/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
body {
font-family: 'Roboto', sans-serif;
margin: 0;
padding: 0;
background: linear-gradient(135deg, #3498db, #8e44ad);
background-size: cover;
color: #ecf0f1;
display: flex;
align-items: center;
justify-content: center;
height: 100vh;
}

.container {
display: flex;
flex-direction: column;
width: 90%;
max-width: 400px;
background-color: rgba(255, 255, 255, 0.9);
padding: 20px;
border-radius: 8px;
box-shadow: 0 0 20px rgba(0, 0, 0, 0.2);
}

h1 {
text-align: center;
color: #2ecc71;
margin-bottom: 20px;
}

p {
text-align: center;
color: #6b6b6b;
margin: 10px 0;
}

#equation {
font-size: 1.2rem;
margin-bottom: 20px;
}

form {
text-align: center;
margin-top: 20px;
margin-bottom: 20px;
color: #6b6b6b;
}

span {
display: inline-block;
margin: 0 10px;
}

input {
font-size: 1rem;
padding: 10px;
margin: 0 10px 10px 10px;
border: 1px solid #ccc;
border-radius: 4px;
box-sizing: border-box;
transition: border-color 0.3s ease, box-shadow 0.3s ease;
color: #2c3e50;
}

input:hover,
input:focus {
border-color: #3498db;
}

form div {
margin-top: 20px;
}

button {
background-color: #e74c3c;
color: #ecf0f1;
padding: 12px 24px;
border: none;
border-radius: 4px;
cursor: pointer;
transition: background-color 0.3s ease;
margin: 0 auto;
display: block;
}

button:hover {
background-color: #c0392b;
}

#output_text {
margin-top: 20px;
text-align: center;
color: #404040;
}

#outputValue {
margin-top: 10px;
font-weight: bold;
font-size: 1.2em;
color: #2ecc71;
}
14 changes: 14 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -1555,6 +1555,20 @@ <h3>Unlock Savings with Precision: Your Ultimate Discount Calculator.</h3>
</div>
</div>
</div>
<div class="box">
<div class="content">
<h2>Discriminant Calculator</h2>
<h3>Calculates the discriminant of a quadratic equation.</h3>
<div class="card-footer">
<a href="./Calculators/Discriminant-Calculator/index.html" target="_blank">
<button>Try Now</button>
</a>
<a href="https://github.com/Rakesh9100/CalcDiverse/tree/main/Calculators/Discriminant-Calculator" title="Source Code" target="_blank">
<img src="./assets/images/github.png" alt="Source Code"></img>
</a>
</div>
</div>
</div>
<div class="box">
<div class="content">
<h2>Dividend Yield Calculator</h2>
Expand Down