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 Dudeney Number Calculator #1631

Merged
merged 17 commits into from
Jul 30, 2024
Merged
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
20 changes: 20 additions & 0 deletions Calculators/Dudeney-Number-Calculator/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# <p align="center">Dudeney Number Calculator</p>

## Description :-

This is a simple website that checks whether an entered number is a Dudeney number or not.

## Tech Stacks :-

- HTML
- CSS
- JavaScript

## Features :-

Displays a clear message indicating if the input is a Dudeney number or not.<br>
Handles queries for large numbers too

## Screenshots :-

![image](https://github.com/user-attachments/assets/df5b21e9-16d2-48f4-b3f3-c4dfa9919d0f)
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
23 changes: 23 additions & 0 deletions Calculators/Dudeney-Number-Calculator/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<link rel="stylesheet" href="style.css">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Dudeney Number Calculator</title>
</head>
<body>
<div class="wrapper">
<header>
<h1>Dudeney Number Calculator</h1>
<p>A Dudeney number is a positive integer that is a perfect cube, and the sum of its digits is equal to the cube root of the number</p>
</header>
<div class="inputs">
<input type="text" spellcheck="false" placeholder="Enter text or number">
<button>Check Dudeney</button>
</div>
<p class="info-txt"></p>
</div>
<script src="script.js"></script>
</body>
</html>
42 changes: 42 additions & 0 deletions Calculators/Dudeney-Number-Calculator/script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
const txtInput = document.querySelector(".inputs input"),
checkBtn = document.querySelector(".inputs button"),
infoTxt = document.querySelector(".info-txt");
let filterInput;

function isDudeneyNumber(num) {
// Find the cube root of the number
const cubeRoot = Math.cbrt(num);

// Check if the cube root is an integer
if (!Number.isInteger(cubeRoot)) {
return false;
}

// Sum the digits of the number
const sumOfDigits = num
.toString()
.split('')
.map(Number)
.reduce((acc, digit) => acc + digit, 0);

// Check if the sum of digits equals the cube root
return sumOfDigits === cubeRoot;
}

checkBtn.addEventListener("click", () => {
let reverseInput = filterInput.split("").reverse().join("");
infoTxt.style.display = "block";
if(!isDudeneyNumber(filterInput)) {
return infoTxt.innerHTML = `No, <span>'${txtInput.value}'</span> isn't a Dudeney Number!`;
}
infoTxt.innerHTML = `Yes, <span>'${txtInput.value}'</span> is a Dudeney Number!`;
});

txtInput.addEventListener("keyup", () => {
filterInput = txtInput.value.toLowerCase().replace(/[^A-Z0-9]/ig, "");
if(filterInput) {
return checkBtn.classList.add("active");
}
infoTxt.style.display = "none";
checkBtn.classList.remove("active");
});
150 changes: 150 additions & 0 deletions Calculators/Dudeney-Number-Calculator/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
@import url('https://fonts.googleapis.com/css2?family=Poppins:wght@400;500;600;700&display=swap');

* {
margin: 0;
padding: 0;
box-sizing: border-box;
font-family: 'Poppins', sans-serif;
}

body {
display: flex;
padding: 0 10px;
background-image: url("assets/background.jpg");
align-items: center;
justify-content: center;
min-height: 100vh;
margin-top: 25px;
background: linear-gradient(-45deg, #ee7752, #e73c7e, #23a6d5, #23d5ab);
background-size: 400% 400%;
animation: gradient 15s ease infinite;
}

::selection {
color: #fff;
background: rgb(170, 87, 204, 0.8);
}

.wrapper {
max-width: 500px;
background: #fff;
border-radius: 7px;
padding: 20px 25px 15px;
box-shadow: 0 15px 40px rgba(0, 0, 0, 0.12);
}

header h1 {
font-size: 27px;
font-weight: 500;
}

header p {
margin-top: 5px;
font-size: 18px;
color: #474747;
}

.inputs {
margin: 20px 0 27px;
}

.inputs input {
width: 100%;
height: 60px;
outline: none;
padding: 0 17px;
font-size: 19px;
border-radius: 5px;
border: 1px solid #999;
transition: 0.1s ease;
}

.inputs input::placeholder {
color: #999999;
}

.inputs input:focus {
box-shadow: 0 3px 6px rgba(0, 0, 0, 0.13);
}

.inputs input:focus::placeholder {
color: #bebebe;
}

.inputs button {
width: 100%;
height: 56px;
border: none;
opacity: 0.7;
outline: none;
color: #fff;
cursor: pointer;
font-size: 17px;
margin-top: 20px;
border-radius: 5px;
pointer-events: none;
background: #AA57CC;
transition: opacity 0.15s ease;
background: linear-gradient(-45deg, #ee7752, #e73c7e, #23a6d5, #23d5ab);
background-size: 400% 400%;
animation: gradient 15s ease infinite;
}

.inputs button.active {
opacity: 1;
pointer-events: auto;
}

.info-txt {
display: none;
font-size: 19px;
text-align: center;
margin-bottom: 18px;
}

.info-txt span {
color: #AA57CC;
}

@media (max-width: 520px) {
.wrapper {
padding: 17px 20px 10px;
}

header h1 {
font-size: 25px;
}

header p {
font-size: 16px;
}

.inputs input {
height: 54px;
font-size: 17px;
}

.inputs button {
height: 50px;
font-size: 16px;
margin-top: 17px;
}

.info-txt {
font-size: 18px;
}
}

@keyframes gradient {
0% {
background-position: 0% 50%;
}

50% {
background-position: 100% 50%;
}

100% {
background-position: 0% 50%;
}
}
14 changes: 14 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -1490,6 +1490,20 @@ <h3>Analyzes dream entries to visualize key themes, emotions, and sentiments.</h
</div>
</div>
</div>
<div class="box">
<div class="content">
<h2>Dudeney Number Calculator</h2>
<h3>Checks if an entered number is Dudeney or not.</h3>
<div class="card-footer">
<a href="./Calculators/Dudeney-Number-Calculator/index.html" target="_blank">
<button>Try Now</button>
</a>
<a href="https://github.com/Rakesh9100/CalcDiverse/tree/main/Calculators/Dudeney-Number-Calculator" title="Source Code" target="_blank">
<img src="./assets/images/github.png" alt="Source Code"></img>
</a>
</div>
</div>
</div>
<div class="box">
<div class="content">
<h2>EBITDA Calculator</h2>
Expand Down