-
Notifications
You must be signed in to change notification settings - Fork 174
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2489 from Saipradyumnagoud/master
Added Letter Combination of a phone number Game
- Loading branch information
Showing
4 changed files
with
147 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,18 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<title>Phone Number Letter Combination</title> | ||
<link rel="stylesheet" href="styles.css"> | ||
</head> | ||
<body> | ||
<div class="container"> | ||
<h1>Phone Number Letter Combination</h1> | ||
<input type="text" id="phone-number" placeholder="Enter phone number" maxlength="10"> | ||
<button onclick="generateCombinations()">Generate Combinations</button> | ||
<div id="combinations"></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,22 @@ | ||
{ | ||
"name": "Phone Number Letter Combination", | ||
"short_name": "LetterCombos", | ||
"description": "A web application that generates all possible letter combinations for a given phone number based on a traditional phone keypad.", | ||
"start_url": "/", | ||
"display": "standalone", | ||
"background_color": "#f0f0f0", | ||
"theme_color": "#4caf50", | ||
"icons": [ | ||
{ | ||
"src": "icons/icon-192x192.png", | ||
"sizes": "192x192", | ||
"type": "image/png" | ||
}, | ||
{ | ||
"src": "icons/icon-512x512.png", | ||
"sizes": "512x512", | ||
"type": "image/png" | ||
} | ||
] | ||
} | ||
|
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,50 @@ | ||
const digitToLetters = { | ||
'2': 'abc', | ||
'3': 'def', | ||
'4': 'ghi', | ||
'5': 'jkl', | ||
'6': 'mno', | ||
'7': 'pqrs', | ||
'8': 'tuv', | ||
'9': 'wxyz' | ||
}; | ||
|
||
function generateCombinations() { | ||
const phoneNumber = document.getElementById('phone-number').value; | ||
const resultContainer = document.getElementById('combinations'); | ||
resultContainer.innerHTML = ''; | ||
|
||
if (!/^[2-9]+$/.test(phoneNumber)) { | ||
resultContainer.innerHTML = '<p>Please enter a valid phone number containing digits 2-9.</p>'; | ||
return; | ||
} | ||
|
||
const combinations = getCombinations(phoneNumber); | ||
|
||
combinations.forEach(combination => { | ||
const p = document.createElement('p'); | ||
p.textContent = combination; | ||
resultContainer.appendChild(p); | ||
}); | ||
} | ||
|
||
function getCombinations(digits) { | ||
if (digits.length === 0) { | ||
return []; | ||
} | ||
if (digits.length === 1) { | ||
return digitToLetters[digits[0]].split(''); | ||
} | ||
|
||
const prevCombinations = getCombinations(digits.slice(0, -1)); | ||
const additionalLetters = digitToLetters[digits[digits.length - 1]]; | ||
const newCombinations = []; | ||
|
||
prevCombinations.forEach(combination => { | ||
for (const letter of additionalLetters) { | ||
newCombinations.push(combination + letter); | ||
} | ||
}); | ||
|
||
return newCombinations; | ||
} |
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,57 @@ | ||
body { | ||
font-family: Arial, sans-serif; | ||
display: flex; | ||
justify-content: center; | ||
align-items: center; | ||
height: 100vh; | ||
margin: 0; | ||
background-color: #f0f0f0; | ||
} | ||
|
||
.container { | ||
text-align: center; | ||
background: white; | ||
padding: 20px; | ||
border-radius: 8px; | ||
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1); | ||
} | ||
|
||
h1 { | ||
margin-bottom: 20px; | ||
} | ||
|
||
input { | ||
padding: 10px; | ||
font-size: 16px; | ||
margin-bottom: 20px; | ||
width: 80%; | ||
max-width: 300px; | ||
border: 1px solid #ccc; | ||
border-radius: 4px; | ||
} | ||
|
||
button { | ||
padding: 10px 20px; | ||
font-size: 16px; | ||
border: none; | ||
border-radius: 5px; | ||
background-color: #4caf50; | ||
color: white; | ||
cursor: pointer; | ||
} | ||
|
||
button:hover { | ||
background-color: #45a049; | ||
} | ||
|
||
#combinations { | ||
margin-top: 20px; | ||
text-align: left; | ||
max-height: 300px; | ||
overflow-y: auto; | ||
} | ||
|
||
#combinations p { | ||
padding: 5px; | ||
border-bottom: 1px solid #ddd; | ||
} |