diff options
Diffstat (limited to 'part1/anecdotes/src/App.js')
-rw-r--r-- | part1/anecdotes/src/App.js | 33 |
1 files changed, 21 insertions, 12 deletions
diff --git a/part1/anecdotes/src/App.js b/part1/anecdotes/src/App.js index efb32a2..4e33e98 100644 --- a/part1/anecdotes/src/App.js +++ b/part1/anecdotes/src/App.js @@ -15,21 +15,30 @@ const Display = (props) => { } const App = () => { - // save clicks of each button to its own state - const [good, setGood] = useState(0) - const [neutral, setNeutral] = useState(0) - const [bad, setBad] = useState(0) + const anecdotes = [ + 'If it hurts, do it more often.', + 'Adding manpower to a late software project makes it later!', + 'The first 90 percent of the code accounts for the first 10 percent of the development time...The remaining 10 percent of the code accounts for the other 90 percent of the development time.', + 'Any fool can write code that a computer can understand. Good programmers write code that humans can understand.', + 'Premature optimization is the root of all evil.', + 'Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.', + 'Programming without an extremely heavy use of console.log is same as if a doctor would refuse to use x-rays or blood tests when diagnosing patients.', + 'The only way to go fast, is to go well.' + + ] + + const [selected, setSelected] = useState(0) + + const getRandomInt = (min, max) => { + min = Math.ceil(min) + max = Math.floor(max) + return Math.floor(Math.random() * (max - min) + min) + } return ( <div> - <h1>give feedback</h1> - <Button onclick={() => setGood(good + 1)} text="good" /> - <Button onclick={() => setNeutral(neutral + 1)} text="neutral" /> - <Button onclick={() => setBad(bad + 1)} text="bad" /> - <h2>statistics</h2> - <Display text="good" count={good} /> - <Display text="neutral" count={neutral} /> - <Display text="bad" count={bad} /> + <p>{anecdotes[selected]}</p> + <Button onclick={() => setSelected(getRandomInt(0, anecdotes.length))} text="next anecdote" /> </div> ) } |