-
Notifications
You must be signed in to change notification settings - Fork 173
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2381 from ANKeshri/feat/add-hcf-calculator
add hcf calculator
- Loading branch information
Showing
6 changed files
with
172 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,18 @@ | ||
# HCF Calculator | ||
|
||
This is a simple and attractive Highest Common Factor (HCF) Calculator built using HTML, CSS, and JavaScript. The design features a neon theme with a linear gradient background, popups for invalid inputs, and a visually appealing user interface. | ||
|
||
## Features | ||
|
||
- Calculate the HCF of two numbers | ||
- Neon-themed UI with gradient background | ||
- Popup for invalid input handling | ||
- Responsive design | ||
|
||
## Files | ||
|
||
The project consists of three main files: | ||
|
||
1. `index.html` - The HTML structure of the calculator. | ||
2. `styles.css` - The CSS file for styling the calculator. | ||
3. `script.js` - The JavaScript file containing the logic for HCF calculation and input validation. |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,24 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<title>HCF Calculator</title> | ||
<link rel="stylesheet" href="styles.css"> | ||
</head> | ||
<body> | ||
<div class="calculator-container"> | ||
<h1>HCF Calculator</h1> | ||
<div class="input-container"> | ||
<input type="number" id="input1" placeholder="Enter number"> | ||
<input type="number" id="input2" placeholder="Enter number"> | ||
<button id="calculate-btn">Calculate HCF</button> | ||
</div> | ||
<div id="result"></div> | ||
</div> | ||
<div id="popup" class="popup"> | ||
<span class="popup-content">Invalid input! Please enter valid numbers.</span> | ||
</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,16 @@ | ||
{ | ||
"manifest_version": 3, | ||
"name": "HCF CALCULATOR", | ||
"version": "1.0", | ||
"description": "A simple game , your aim is to protect rabbit from wolf", | ||
"action": { | ||
"default_popup": "index.html", | ||
"default_icon": "image.png" | ||
}, | ||
"icons": { | ||
"16": "image.png", | ||
"48": "image.png", | ||
"128": "image.png" | ||
}, | ||
"permissions":[] | ||
} |
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,21 @@ | ||
document.getElementById('calculate-btn').addEventListener('click', function() { | ||
const num1 = parseInt(document.getElementById('input1').value); | ||
const num2 = parseInt(document.getElementById('input2').value); | ||
|
||
if (isNaN(num1) || isNaN(num2) || num1 < 0 || num2 < 0) { | ||
document.getElementById('popup').classList.add('active'); | ||
setTimeout(function() { | ||
document.getElementById('popup').classList.remove('active'); | ||
}, 3000); // Hide popup after 3 seconds | ||
} else { | ||
const hcf = calculateHCF(num1, num2); | ||
document.getElementById('result').innerText = `HCF of ${num1} and ${num2} is ${hcf}`; | ||
} | ||
}); | ||
|
||
function calculateHCF(a, b) { | ||
if (b === 0) { | ||
return a; | ||
} | ||
return calculateHCF(b, a % b); | ||
} |
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,93 @@ | ||
body { | ||
font-family: Arial, sans-serif; | ||
background: linear-gradient(to right, #7F00FF, #E100FF); /* Replace with your preferred gradient colors */ | ||
color: white; | ||
display: flex; | ||
justify-content: center; | ||
align-items: center; | ||
height: 100vh; | ||
margin: 0; | ||
} | ||
|
||
.calculator-container { | ||
text-align: center; | ||
padding: 20px; | ||
border-radius: 10px; | ||
background-color: rgba(0, 0, 0, 0.5); | ||
box-shadow: 0 0 20px rgba(0, 0, 0, 0.5); | ||
} | ||
|
||
h1 { | ||
font-size: 2.5rem; | ||
color: #FF355E; /* Neon red color */ | ||
margin-bottom: 20px; | ||
} | ||
|
||
.input-container { | ||
margin-top: 20px; | ||
} | ||
|
||
input[type="number"], button { | ||
padding: 10px; | ||
font-size: 1rem; | ||
border: none; | ||
outline: none; | ||
margin: 5px; | ||
border-radius: 5px; | ||
} | ||
|
||
button { | ||
cursor: pointer; | ||
background-color: #FF355E; /* Neon red color */ | ||
color: white; | ||
transition: background-color 0.3s ease; | ||
padding: 12px 20px; | ||
font-size: 1.2rem; | ||
border-radius: 8px; | ||
border: 2px solid #FF355E; | ||
} | ||
|
||
button:hover { | ||
background-color: #FF1493; /* Lighter shade of red */ | ||
border-color: #FF1493; | ||
} | ||
|
||
#result { | ||
margin-top: 20px; | ||
font-size: 1.5rem; | ||
color: #00FFEE; /* Neon color */ | ||
} | ||
|
||
.popup { | ||
display: none; | ||
position: fixed; | ||
top: 30%; /* Adjust top position as needed */ | ||
left: 50%; | ||
transform: translateX(-50%); | ||
background-color: black; | ||
padding: 20px; | ||
border-radius: 10px; | ||
color: white; | ||
z-index: 999; | ||
text-align: center; | ||
} | ||
|
||
.popup-content { | ||
font-size: 1.2rem; | ||
} | ||
|
||
.popup.active { | ||
display: block; | ||
animation: popupAppear 0.5s ease forwards; | ||
} | ||
|
||
@keyframes popupAppear { | ||
0% { | ||
opacity: 0; | ||
transform: translate(-50%, -60%); | ||
} | ||
100% { | ||
opacity: 1; | ||
transform: translate(-50%, -30%); | ||
} | ||
} |