Skip to content

Commit

Permalink
prime
Browse files Browse the repository at this point in the history
  • Loading branch information
Jayesh-JainX committed Oct 11, 2023
2 parents bd26548 + 524bb48 commit c823e7e
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 8 deletions.
1 change: 1 addition & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ <h1>Prime Number Checker</h1>
<div class="search-history-header">
<h2>Search History</h2>
<button id="clearHistoryButton">Clear History</button>
<div id="message">&nbsp;History Cleared&nbsp;</div>
</div>
<table id="historyTable">
<thead>
Expand Down
25 changes: 18 additions & 7 deletions script.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,26 +14,40 @@ function isPrime(num) {
function clearHistory() {
localStorage.removeItem('searchHistory');
const historyBody = document.getElementById('historyBody');
const message = document.getElementById('message');
historyBody.innerHTML = '';
let isMessageVisible = false;
if (!isMessageVisible) {
message.style.animation = 'none';
void message.offsetWidth;
message.style.animation = null;
message.style.display = 'block';
isMessageVisible = true;

setTimeout(() => {
message.style.display = 'none';
isMessageVisible = false;
}, 3000);
}
}

const clearHistoryButton = document.getElementById('clearHistoryButton');
clearHistoryButton.addEventListener('click', clearHistory);



function checkPrime() {
const numberInput = document.getElementById('numberInput').value;
const resultElement = document.getElementById('result');
const historyTable = document.getElementById('historyTable');
const historyBody = document.getElementById('historyBody');

// Input validation
if (numberInput === '' || isNaN(numberInput)) {
resultElement.textContent = 'Please enter a Valid Number';
return;
}

// Check for a large number input
if (BigInt(numberInput) >= 10n**308n) {
if (BigInt(numberInput) >= 10n ** 308n) {
resultElement.textContent = 'Maximum Limit Reached';
return;
}
Expand All @@ -48,14 +62,12 @@ function checkPrime() {
const searchHistory = JSON.parse(localStorage.getItem('searchHistory')) || [];
searchHistory.push({ number: numberInput, isPrime: isPrimeResult });

// Limit displayed history entries (e.g., to the last 10)
if (searchHistory.length > 10) {
searchHistory.shift();
}

localStorage.setItem('searchHistory', JSON.stringify(searchHistory));

// Update displayed history
historyBody.innerHTML = '';
searchHistory.forEach((item) => {
const row = document.createElement('tr');
Expand All @@ -75,8 +87,7 @@ window.addEventListener('load', () => {
const historyBody = document.getElementById('historyBody');
const searchHistory = JSON.parse(localStorage.getItem('searchHistory')) || [];

// Display a limited number of history entries
const displayedHistory = searchHistory.slice(-10); // Display the last 10 entries
const displayedHistory = searchHistory.slice(-100);
displayedHistory.forEach((item) => {
const row = document.createElement('tr');
const numberCell = document.createElement('td');
Expand Down
20 changes: 19 additions & 1 deletion style.css
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ p#result {
margin-bottom: 110px;
}

/* Style the Search History heading and "Clear History" button */
.search-history-header {
display: flex;
justify-content: space-between;
Expand Down Expand Up @@ -118,6 +117,25 @@ tr:hover {
transition: background-color 0.3s ease-in-out;
}

#message {
display: none;
background-color: #585555;
color: white;
padding: 10px;
border-radius: 18px;
position: absolute;
bottom: 15%;
left: 50%;
transform: translateX(-50%);
animation: fadeOut 3s ease-in-out;
}

@keyframes fadeOut {
0% { opacity: 1; }
90% { opacity: 1; }
100% { opacity: 0; display: none; }
}

footer {
position: fixed;
bottom: 0;
Expand Down

0 comments on commit c823e7e

Please sign in to comment.