JSFiddle - React, Tailwind, and code Playground
HTML
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Random Qoute Generator</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<h1>Random Quote Generator</h1>
<div class="quote-container">
<p id="quote">"Succus is not final"</p>
<p id="writer-name">― anonymous</p>
<button id="generate-quote-btn">Generate Quote</button>
<div class = "mood">
<button id="happy-quote-btn">Happy</button>
<button id="sad-quote-btn">Sad</button>
<button id="motivated-quote-btn">Motivated</button>
</div>
</div>
<script src="script.js"></script>
</body>
</html>
CSS
*{
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: Arial, Helvetica, sans-serif;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
background-color: rgba(215, 78, 215, 0.322);
gap: 10px;
}
.quote-container{
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
background-color: white;
width: 500px;
height: 400px;
margin: 20px;
border-radius: 5px;
box-shadow: 2px 2px 5px rgb(180, 179, 179), -2px -2px 5px rgb(180, 179, 179);
gap: 10px;
}
h1{
margin-top: 10px;
font-size: 2.5rem;
font-weight: 900;
}
p {
font-size: 1.4em;
}
#quote {
font-family: cursive;
padding: 10px;
text-align: center;
width: 300px;
}
button{
padding: 10px 20px;
border: none;
border-radius: 5px;
font-size: 18px;
color: white;
margin-top: 10px;
}
#generate-quote-btn{
background-color: rgb(69, 125, 237);
}
#generate-quote-btn:hover {
cursor: pointer;
}
.mood{
display: flex;
justify-content: center;
align-items: center;
gap: 10px;
}
#happy-quote-btn{
background-color: #F9C74F;
}
#sad-quote-btn{
background-color: #095fab;
}
#motivated-quote-btn{
background-color: #F94144;
}
JavaScript
(() => {
const IS_DEBUG = false;
const COLORS = Object.freeze([
'#F94144',
'#577590',
'#43AA8B',
'#F9C74F',
'#9D4EDD',
]);
const TYPE = Object.freeze({
sad: 'sad',
motivated: 'motivated',
happy: 'happy',
});
const QUOTES = Object.freeze([
Object.freeze({
text: 'Be yourself; everyone else is already taken.',
author: 'Oscar Wilde',
type: TYPE.motivated,
}),
Object.freeze({
text: 'You only live once, but if you do it right, once is enough.',
author: 'Mae West',
type: TYPE.happy,
}),
Object.freeze({
text: 'So many books, so little time.',
author: 'Frank Zappa',
type: TYPE.sad,
}),
Object.freeze({
text: 'A room without books is like a body without a soul.',
author: 'Marcus Tullius Cicero',
type: TYPE.motivated,
}),
Object.freeze({
text: 'Be the change that you wish to see in the world.',
author: 'Mahatma Gandhi',
type: TYPE.happy,
}),
]);
const HAPPY = QUOTES.filter($ => TYPE.happy === $.type);
const SAD = QUOTES.filter($ => TYPE.sad === $.type);
const MOTIVATED = QUOTES.filter(quote => TYPE.motivated === quote.type);
if (IS_DEBUG) console.log('Categorized quotes:', {HAPPY, SAD});
const EL = Object.entries({
background: 'body',
heading: 'h1',
quote: '#quote',
writer: '#writer-name',
generate: '#generate-quote-btn',
happy: '#happy-quote-btn',
sad: '#sad-quote-btn',
motivated: '#motivated-quote-btn',
}).reduce((object, [name, selector]) => {
object[name] = document.querySelector(selector);
return...