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 Prime Number Calculator #1810

Closed
Closed
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Calculators/Prime-Number-Finder/assets/star.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
24 changes: 24 additions & 0 deletions Calculators/Prime-Number-Finder/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Prime Number Finder</title>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<div class="container">
<h1>Prime Number Finder</h1>
<div class="calculator">
<p>Enter a number to check if it's a prime number.</p>
<input type="number" id="numberInput" min="1">
<button onclick="checkPrime()">Check</button>
<p id="result"></p>
<img id="starImage" src="assets/star.jpeg" alt="Star" style="display: none;">
</div>
</div>
<script src="script.js"></script>
</body>
</html>


27 changes: 27 additions & 0 deletions Calculators/Prime-Number-Finder/script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
function checkPrime() {
const number = parseInt(document.getElementById('numberInput').value);
const resultElement = document.getElementById('result');
const starImage = document.getElementById('starImage');

if (number <= 1) {
resultElement.textContent = `${number} is not a prime number.`;
starImage.style.display = 'none';
return;
}

let isPrime = true;
for (let i = 2; i <= Math.sqrt(number); i++) {
if (number % i === 0) {
isPrime = false;
break;
}
}

if (isPrime) {
resultElement.textContent = `${number} is a prime number!`;
starImage.style.display = 'inline';
} else {
resultElement.textContent = `${number} is not a prime number.`;
starImage.style.display = 'none';
}
}
78 changes: 78 additions & 0 deletions Calculators/Prime-Number-Finder/styles.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
body {
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
margin: 0;
background-image: url('assets/background.jpg');
background-size: cover;
background-position: center;
background-repeat: no-repeat;
background-attachment: fixed;
background-color: #e0e0e0;
}

.container {
background-color: black;
opacity: .8;
padding: 2rem;
border-radius: 12px;
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
text-align: center;
max-width: 400px;
width: 100%;
}

h1 {
color: white;
font-size: 1.8rem;
margin-bottom: 1rem;
}

.calculator {
margin-top: 1.5rem;
color: white;
}

input {
padding: 0.75rem;
font-size: 1rem;
width: 100%;
max-width: 220px;
margin-bottom: 1rem;
border: 1px solid #ddd;
border-radius: 6px;
box-sizing: border-box;
}

button {
padding: 0.75rem 1.25rem;
font-size: 1rem;
background-color: #3498db;
color: #ffffff;
border: none;
border-radius: 6px;
cursor: pointer;
transition: background-color 0.3s, transform 0.2s;
}

button:hover {
background-color: #2980b9;
transform: translateY(-2px);
}

#result {
margin-top: 1.5rem;
font-weight: bold;
color: #e74c3c;
font-size: 1.2rem;
}

#starImage {
width: 60px;
height: 60px;
margin-top: 1.5rem;
border-radius: 50%;
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
}
16 changes: 16 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3853,6 +3853,22 @@ <h3>Calculates the prime factors of the given number.</h3>
</div>
</div>
</div>
<div class="container">
<div class="box">
<div class="content">
<h2>Prime Number Finder</h2>
<h3>Calculates whether given number is Prime or not</h3>
<div class="card-footer">
<a href="./Calculators/Prime-Number-Finder/index.html" target="_blank">
<button>Try Now</button>
</a>
<a href="https://github.com/Rakesh9100/CalcDiverse/tree/main/Calculators/Prime-Number-Finder" title="Source Code" target="_blank">
<img src="./assets/images/github.png" alt="Source Code">
</a>
</div>
</div>
</div>
</div>
<div class="box">
<div class="content">
<h2>Probability Calculator</h2>
Expand Down