Skip to content

Commit

Permalink
Added Neon Number Calculator (#574)
Browse files Browse the repository at this point in the history
  • Loading branch information
AftabMankapure authored Feb 11, 2024
1 parent 88ac03f commit 9e6d47e
Show file tree
Hide file tree
Showing 5 changed files with 206 additions and 0 deletions.
25 changes: 25 additions & 0 deletions Calculators/Neon-Number-Calculator/README.md
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)
38 changes: 38 additions & 0 deletions Calculators/Neon-Number-Calculator/index.html
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>
50 changes: 50 additions & 0 deletions Calculators/Neon-Number-Calculator/script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
function checkNeonNumber() {
let number = document.getElementById('number').value;

if (!validateInput(number)) {
alert('Please enter a valid positive integer.');
return;
}

let result = isNeonNumber(number);

document.getElementById('resultSingle').innerText = `${number} is ${result.isNeon ? '' : '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 /^(0|[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}.`
};
}
79 changes: 79 additions & 0 deletions Calculators/Neon-Number-Calculator/style.css
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;
}
14 changes: 14 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -1779,6 +1779,20 @@ <h3>Compute stress and strain using force, area, and length inputs.</h3>
</div>
</div>
</div>
<div class="box">
<div class="content">
<h2>Neon Number Calculator</h2>
<h3>Checks the number is neon or not and finds neon numbers in a range.</h3>
<div class="card-footer">
<a href="./Calculators/Neon-Number-Calculator/index.html" target="_blank">
<button>Try Now</button>
</a>
<a href="https://github.com/Rakesh9100/CalcDiverse/tree/main/Calculators/Neon-Number-Calculator" title="Source Code" target="_blank">
<img src="./assets/images/github.png" alt="Source Code"></img>
</a>
</div>
</div>
</div>
</div>

<!-- Calculator Section Ends Here -->
Expand Down

0 comments on commit 9e6d47e

Please sign in to comment.