-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
33 lines (28 loc) · 1.44 KB
/
Copy pathscript.js
File metadata and controls
33 lines (28 loc) · 1.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
function RandomQuoteMachine() {
const arr = ['"The purpose of our lives is to be happy." — Dalai Lama',
'"Life is what happens when you are busy making other plans." — John Lennon',
'"Get busy living or get busy dying." — Stephen King',
'"You only live once, but if you do it right, once is enough." — Mae West',
'"Many of life’s failures are people who did not realize how close they were to success when they gave up."– Thomas A. Edison'
];
const [quote, setQuote] = React.useState("Click the button below!");
const [bgColor, setbgColor] = React.useState("#fff");
const randomClick = () => {
const randomQuote = arr[Math.floor(Math.random()*arr.length)]
setQuote(randomQuote)
};
const bgColorClick = () => {
const randombgColor = '#' + Math.random().toString(16).slice(2,8);
setbgColor(randombgColor)
}
return (
<div class='d-flex justify-content-center align-items-center flex-column vw-100 vh-100' style={{backgroundColor: `${bgColor}`}}>
<h1 class='text-center mb-5'>Random-Quote-Machine</h1>
<h2 class='bg-light rounded p-3'>{quote}</h2>
<div class='text-center mt-5'>
<button class='btn btn-primary' type='button' onClick={() => {bgColorClick(); randomClick()}}>Try again</button>
</div>
</div>
)
}
ReactDOM.render(<RandomQuoteMachine />, document.getElementById('root'));