-
Notifications
You must be signed in to change notification settings - Fork 394
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6a7ded5
commit 85bea3c
Showing
4 changed files
with
196 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,25 @@ | ||
# <p align="center">Neon Number Calculator</p> | ||
|
||
## Description: | ||
|
||
Neon Number Calculator is a web application that allows users to check if a given number is a neon number and find neon numbers within a specified range. | ||
|
||
- Checks if a number is a neon number. | ||
- Finds neon numbers within a specified range. | ||
- Responsive design for multiple devices. | ||
|
||
## What is a Neon Number? | ||
|
||
A neon number is a number where the sum of its digits, when squared, equals the original number. Mathematically, for a given number 'n', if the sum of the digits of n^2 is equal to n, then it is a neon number. | ||
|
||
For example, 9 is a neon number because 9^2 = 81, and the sum of the digits of 81 is 8 + 1 = 9. | ||
|
||
## Tech Stacks: | ||
|
||
- HTML | ||
- CSS | ||
- JavaScript | ||
|
||
## Screenshots: | ||
|
||
![Neon](https://github.com/Rakesh9100/CalcDiverse/assets/125949765/db79ecfe-1faa-4f01-9b63-f01f750a7781) |
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,38 @@ | ||
<!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>Neon Number Calculator</title> | ||
</head> | ||
|
||
<body> | ||
|
||
<h1 class="title">Neon Number Calculator</h1> | ||
|
||
<div class="calculator"> | ||
<div class="section"> | ||
<p class="calculator-title">Check Single Neon Number</p> | ||
<label for="number">Enter a number:</label> | ||
<input type="number" id="number" placeholder="Enter a number"> | ||
<button onclick="checkNeonNumber()">Check</button> | ||
<p id="resultSingle"></p> | ||
</div> | ||
|
||
<div class="section"> | ||
<p class="calculator-title">Check Neon Numbers in Range</p> | ||
<label for="fromRange">From:</label> | ||
<input type="number" id="fromRange" placeholder="Enter from number"> | ||
<label for="toRange">To:</label> | ||
<input type="number" id="toRange" placeholder="Enter to number"> | ||
<button onclick="checkNeonNumbersInRange()">Check</button> | ||
<p id="rangeResult"></p> | ||
</div> | ||
</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,54 @@ | ||
function checkNeonNumber() { | ||
let number = document.getElementById('number').value; | ||
|
||
if (!validateInput(number)) { | ||
alert('Please enter a valid positive integer.'); | ||
return; | ||
} | ||
|
||
let result = isNeonNumber(number); | ||
|
||
if (result.isNeon) { | ||
document.getElementById('resultSingle').innerText = `${number} is a Neon number.`; | ||
} else { | ||
document.getElementById('resultSingle').innerText = `${number} is not a Neon number. ${result.explanation}`; | ||
} | ||
} | ||
|
||
function checkNeonNumbersInRange() { | ||
let fromRange = parseInt(document.getElementById('fromRange').value); | ||
let toRange = parseInt(document.getElementById('toRange').value); | ||
|
||
if (isNaN(fromRange) || isNaN(toRange) || fromRange >= toRange) { | ||
alert('Please enter valid range values.'); | ||
return; | ||
} | ||
|
||
let neonNumbers = []; | ||
|
||
for (let i = fromRange; i <= toRange; i++) { | ||
if (isNeonNumber(i.toString()).isNeon) { | ||
neonNumbers.push(i); | ||
} | ||
} | ||
|
||
if (neonNumbers.length > 0) { | ||
document.getElementById('rangeResult').innerText = `Neon numbers in the range ${fromRange} to ${toRange}: ${neonNumbers.join(', ')}`; | ||
} else { | ||
document.getElementById('rangeResult').innerText = `There are no Neon numbers in the range ${fromRange} to ${toRange}.`; | ||
} | ||
} | ||
|
||
function validateInput(number) { | ||
return /^[1-9]\d*$/.test(number); | ||
} | ||
|
||
function isNeonNumber(number) { | ||
let square = parseInt(number) ** 2; | ||
let digitSum = Array.from(square.toString()).reduce((acc, digit) => acc + parseInt(digit), 0); | ||
|
||
return { | ||
isNeon: digitSum === parseInt(number), | ||
explanation: `The square of ${number} is ${square}. The sum of its digits is ${digitSum}.` | ||
}; | ||
} |
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,79 @@ | ||
body { | ||
font-family: 'Arial', sans-serif; | ||
text-align: center; | ||
margin: 0; | ||
padding: 0; | ||
background-color: #000; | ||
color: #fff; | ||
} | ||
|
||
.calculator { | ||
display: flex; | ||
justify-content: space-around; | ||
align-items: flex-start; /* Adjusted alignment */ | ||
margin: 50px auto; | ||
max-width: 900px; | ||
} | ||
|
||
.section { | ||
width: 45%; | ||
padding: 20px; | ||
box-sizing: border-box; | ||
background-color: #000; | ||
border: 1px solid #00f; | ||
border-radius: 15px; | ||
box-shadow: 0 0 20px rgba(0, 255, 255, 0.8); | ||
margin-bottom: 20px; | ||
} | ||
|
||
input { | ||
padding: 10px; | ||
font-size: 16px; | ||
margin-top: 10px; | ||
width: 100%; | ||
box-sizing: border-box; | ||
} | ||
|
||
button { | ||
padding: 10px 20px; | ||
font-size: 16px; | ||
cursor: pointer; | ||
background-color: #00f; | ||
color: #fff; | ||
border: none; | ||
border-radius: 5px; | ||
margin-top: 10px; | ||
transition: background-color 0.3s, box-shadow 0.3s; | ||
} | ||
|
||
button:hover { | ||
background-color: #003366; | ||
box-shadow: 0 0 20px rgba(0, 255, 255, 0.8); | ||
} | ||
|
||
p { | ||
font-size: 18px; | ||
margin-top: 20px; | ||
color: #fff; | ||
} | ||
|
||
.title { | ||
padding: 20px; | ||
margin: 0; | ||
font-size: 36px; | ||
font-weight: 900; | ||
color: yellow; | ||
transition: color 0.3s, transform 0.3s; | ||
} | ||
|
||
.title:hover { | ||
color: red; | ||
transform: scale(1.1); | ||
} | ||
|
||
.calculator-title { | ||
color: #4caf50; | ||
font-size: 24px; | ||
font-weight: bold; | ||
margin-bottom: 15px; | ||
} |