Skip to content

Commit

Permalink
Added Ugly Number Calculator Rakesh9100#1012
Browse files Browse the repository at this point in the history
  • Loading branch information
Anshika14528 committed Jun 6, 2024
1 parent 551f76e commit 82f946e
Show file tree
Hide file tree
Showing 6 changed files with 688 additions and 243 deletions.
27 changes: 27 additions & 0 deletions Calculators/Ugly-Number-Calculator/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# <p align="center">Ugly Number Calculator</p>

## Description :-

This is a simple web application that allows users to check if a given number is a ugly number or not.
An ugly number is a positive integer whose prime factors are limited to 2, 3, and 5.
For example, 6 is a ugly number as it have only 2 and 3 as prime factor.

## Tech Stacks :-

- HTML
- CSS
- JavaScript

## Features :-

- Users can input a number.
- Upon clicking the "Check for ugly" button, the application checks whether the entered number is a ugly number or not.
- The result is displayed below the input field, indicating whether the number is ugly or not.

## Screenshots :-

![image]()

![image]()

![image]()
Binary file not shown.
28 changes: 28 additions & 0 deletions Calculators/Ugly-Number-Calculator/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Ugly Number Calculator</title>
<link rel="stylesheet" href="style.css">
</head>

<body>
<header>
<h1>Ugly Number Checker Calculator</h1>
</header>
<main>
<div class="container">
<label for="no">Enter the Number : </label>
<input type="number" placeholder="Enter number(n)" class="number" required>
<button onclick="checkUgly()">Check for Ugly</button>
<h2 class="text"></h2>
<h3 class="showHow"></h3>

</div>
</main>
<script src="script.js"></script>
</body>

</html>
64 changes: 64 additions & 0 deletions Calculators/Ugly-Number-Calculator/script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
// to check if a number is Ugly or not :
const checkUgly = () => {
let n = document.querySelector(".number").value;
let txt = document.querySelector(".text");
let how = document.querySelector(".showHow");
let p = n;
if (n === "" || Number.isNaN(n)) {
txt.textContent = `("Please enter a number ")`;
how.textContent = ``
}
else {
if (n <= 0) {
txt.textContent = ("Please enter a valid number ");
how.textContent = ``;
}
else {
let flag = 0;
while (n != 1) {
if (n % 2 === 0) {
n /= 2
} else if (n % 3 === 0) {
n /= 3
} else if (n % 5 === 0) {
n /= 5
} else {
flag = 1;
txt.textContent = (`${p} is not a Ugly Number!`);

how.textContent = (`Proof: (${((prime_factors(p).join(", ")))}): are distinct prime factors of ${p} which does not belongs from prime numbers( 2, 3, 5) `);
break;
}
}

if (flag == 0) {
txt.textContent = (`${p} is a Ugly Number!`);
how.textContent = (`Proof: (${((prime_factors(p).join(", ")))}): are distinct prime factors of ${p} which belongs from prime numbers( 2, 3, 5)`);
}
}

}
}

// Function to get all distinct prime factors of a number :
function prime_factors(num) {
// Function to check if a number is prime
function is_prime(num) {
for (let i = 2; i <= Math.sqrt(num); i++) {
if (num % i === 0) return false;
}
return true;
}

const result = []; // Initialize an empty array to store prime factors

for (let i = 2; i <= num; i++) {

while (is_prime(i) && num % i === 0) {
if (!result.includes(i)) result.push(i); // Add 'i' to the result array if it's not already present
num /= i;
}
}

return result; // Return the array containing prime factors
}
77 changes: 77 additions & 0 deletions Calculators/Ugly-Number-Calculator/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
body {
font-family: Arial, sans-serif;
background-image: url('assets/background.avif');
background-size: cover;
background-position: center;
background-color: rgb(158, 27, 158);
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
height: 100vh;

}

header {
color: rgb(255, 255, 255);
margin-bottom: 40px;
font-weight: bold;
font-size: large;
text-decoration: underline;
text-decoration-color: rgb(255, 255, 255);
}

h2 {
color: #12015d;
margin-bottom: 40px;
font-weight: bold;

}

h3 {
color: rgb(39, 38, 38);
margin-bottom: 40px;
font-weight: bold;
}


.container {
display: flex;
flex-direction: column;
color: rgb(195, 0, 143);
font-weight: bold;
font-size: larger;
align-items: center;
justify-content: center;
background: linear-gradient(to right, #f84b6a, #39afef);
border-radius: 30px;
padding: 100px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
border: #379df6;

}

label {
margin-bottom: 20px;
color: #9b016d;
}

input {
padding: 8px;
margin-bottom: 20px;
width: 150px;
border: #b3f32b
}

button {
padding: 10px;
background-color: rgb(249, 50, 196);
color: white;
border: none;
cursor: pointer;
font-size: medium;
}

button:hover {
background-color: #c518fa;
}
Loading

0 comments on commit 82f946e

Please sign in to comment.