-
Notifications
You must be signed in to change notification settings - Fork 403
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added Lottery Odds Calculator (#1762)
- Loading branch information
Showing
5 changed files
with
155 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,15 @@ | ||
# <p align="center">Lottery Odds Calculator</p> | ||
|
||
## Description :- | ||
|
||
A calculator that calculates your chances of winning the lottery by taking the input as the number of tickets sold and the number of tickets bought by you. | ||
|
||
## Tech Stacks :- | ||
|
||
- HTML | ||
- CSS | ||
- JavaScript | ||
|
||
## Screenshots :- | ||
|
||
![image](https://github.com/user-attachments/assets/c850c5f9-19e7-4e12-bcf2-606661176d74) |
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,33 @@ | ||
<!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>Lottery Odds Calculator</title> | ||
</head> | ||
|
||
<body> | ||
<header> | ||
<h1>Lottery Odds Calculator</h1> | ||
</header> | ||
|
||
<section id="calculator"> | ||
<label for="tickets" style="font-size: 18px; font-weight:bold; ">Enter the number of tickets you bought:</label> | ||
<input type="number" id="tickets" required> | ||
|
||
<label for="sold" style="font-size: 18px; font-weight:bold;">Enter the total number of tickets sold:</label> | ||
<input type="number" id="sold" required> | ||
|
||
<button onclick="calculate()">Calculate</button> | ||
<br> | ||
<br> | ||
<span style="font-weight:bold; font-size:16px;">Your chances of winning the lottery are:</span> | ||
<p id="result"></p> | ||
</section> | ||
|
||
<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,21 @@ | ||
function calculate() { | ||
// Get input values | ||
const tickets = parseFloat(document.getElementById('tickets').value); | ||
const sold = parseFloat(document.getElementById('sold').value); | ||
|
||
// Validate inputs | ||
if (isNaN(tickets) || isNaN(sold) || sold <= 0) { | ||
document.getElementById('result').textContent = 'Please enter the values'; | ||
return; | ||
} | ||
|
||
// Perform the calculation | ||
let r = tickets / sold; | ||
r = r * 100; | ||
let result = r.toFixed(2); // Limit to two decimal places | ||
result += "%"; | ||
|
||
// Display the result | ||
const resultElement = document.getElementById('result'); | ||
resultElement.textContent = result; | ||
} |
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,72 @@ | ||
body { | ||
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; | ||
margin: 0; | ||
padding: 0; | ||
background-color: #aaf0dd; | ||
} | ||
|
||
header { | ||
background-color: #3c25e8; | ||
color: #fff; | ||
text-align: center; | ||
padding: 1em; | ||
} | ||
|
||
#calculator { | ||
max-width: 300px; | ||
margin: 20px auto; | ||
border: 2px solid #0c0101; | ||
padding: 20px; | ||
border-radius: 8px; | ||
background: linear-gradient(to right, #deec76, #15df0e); | ||
background-color: #fff; | ||
box-shadow: 0 0 10px rgba(0, 0, 0, 0.2); | ||
text-align: center; | ||
} | ||
|
||
label { | ||
display: block; | ||
margin-bottom: 8px; | ||
color: #333; | ||
} | ||
|
||
input, | ||
select { | ||
width: 100%; | ||
padding: 10px; | ||
margin-bottom: 16px; | ||
box-sizing: border-box; | ||
border-radius: 9px; | ||
} | ||
|
||
button { | ||
width: 100%; | ||
height: 40px; | ||
font-size: 16px; | ||
cursor: pointer; | ||
background-color: #103cee; | ||
color: #fff; | ||
border: none; | ||
border-radius: 9px; | ||
transition: background-color 0.3s; | ||
} | ||
|
||
button:hover { | ||
background-color: #45a09e; | ||
} | ||
|
||
#result { | ||
margin-top: 16px; | ||
font-weight: bold; | ||
color: red; | ||
text-align: center; | ||
font-size: 22px; | ||
} | ||
|
||
#base { | ||
font-weight: bold; | ||
} | ||
|
||
#value { | ||
font-weight: bold; | ||
} |
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