npx create-react-app random-quote-app
cd random-quote-app
npm install bootstrap
import 'bootstrap/dist/css/bootstrap.min.css';
import React, { useState } from 'react';
import RandomQuote from './RandomQuote';
const quotes = [
{ author: "Albert Einstein", content: "Life is like riding a bicycle. To keep your balance you must keep moving." },
{ author: "Maya Angelou", content: "You will face many defeats in life, but never let yourself be defeated." },
{ author: "Oscar Wilde", content: "Be yourself; everyone else is already taken." },
{ author: "Mark Twain", content: "The secret of getting ahead is getting started." },
{author: "Dennis Prager", content:"Goodness is about character - integrity, honesty, kindness, generosity, moral courage, and the like. More than anything else, it is about how we treat other people." },
];
function App() {
const [quote, setQuote] = useState(quotes[0]);
const [color, setColor] = useState('#17a2b8');
const getRandomQuote = () => {
const randomIndex = Math.floor(Math.random() * quotes.length);
const randomColor = `#${Math.floor(Math.random() * 16777215).toString(16)}`;
setQuote(quotes[randomIndex]);
setColor(randomColor);
};
return (
<div className="d-flex flex-column align-items-center justify-content-center vh-100" style={{ backgroundColor: color, color: 'white' }}>
<RandomQuote
quote={quote}
color={color}
onChangeQuote={getRandomQuote}
/>
</div>
);
}
export default App;
import React from 'react';
function RandomQuote({ quote, color, onChangeQuote }) {
return (
<div className="p-4 bg-white rounded shadow text-center" style={{ color: color }}>
<p className="mb-3" style={{ fontSize: '1.5rem' }}>"{quote.content}"</p>
<p className="mb-4 fw-bold fst-italic">- {quote.author}</p>
<button className="btn btn-primary" onClick={onChangeQuote}>
Get New Quote
</button>
</div>
);
}
export default RandomQuote;