Random Word Generator
/* Global Styles */
* {
margin: 0;
padding: 0;
box-sizing: border-box;
font-family: 'Arial', sans-serif;
}
body {
background: linear-gradient(135deg, #f06, #4a90e2);
color: #fff;
display: flex;
justify-content: center;
align-items: center;
min-height: 100vh;
padding: 20px;
}
.container {
background-color: rgba(0, 0, 0, 0.7);
border-radius: 10px;
padding: 30px;
max-width: 500px;
text-align: center;
box-shadow: 0 4px 15px rgba(0, 0, 0, 0.5);
}
h1 {
margin-bottom: 20px;
font-size: 2rem;
text-transform: uppercase;
letter-spacing: 3px;
}
.controls {
margin-bottom: 20px;
}
#word-count {
width: 70%;
padding: 10px;
margin-right: 10px;
border-radius: 5px;
border: none;
font-size: 1rem;
}
#generate-btn {
padding: 10px 20px;
border: none;
background-color: #4a90e2;
color: #fff;
border-radius: 5px;
font-size: 1rem;
cursor: pointer;
transition: background-color 0.3s ease;
}
#generate-btn:hover {
background-color: #f06;
}
.output {
margin-top: 20px;
display: flex;
flex-wrap: wrap;
gap: 10px;
justify-content: center;
}
.word {
padding: 10px 15px;
border-radius: 5px;
font-size: 1rem;
background-color: rgba(255, 255, 255, 0.2);
text-shadow: 1px 1px 3px rgba(0, 0, 0, 0.5);
animation: fadeIn 0.5s ease;
}
/* Responsive Design */
@media (max-width: 600px) {
h1 {
font-size: 1.5rem;
}
#word-count {
width: 100%;
margin-bottom: 10px;
}
#generate-btn {
width: 100%;
}
}
/* Animations */
@keyframes fadeIn {
from {
opacity: 0;
transform: translateY(20px);
}
to {
opacity: 1;
transform: translateY(0);
}
}
document.getElementById('generate-btn').addEventListener('click', () => {
const wordCount = parseInt(document.getElementById('word-count').value, 10);
const outputDiv = document.getElementById('output');
outputDiv.innerHTML = ''; // Clear previous words
if (!wordCount || wordCount <= 0 || wordCount > 50) {
outputDiv.innerHTML = '
Please enter a valid number between 1 and 50.
';
return;
}
// Generate random words using Chance.js
for (let i = 0; i < wordCount; i++) {
const randomWord = chance.word();
const wordElement = document.createElement('div');
wordElement.classList.add('word');
wordElement.textContent = randomWord;
outputDiv.appendChild(wordElement);
}
});