exercise 1.13
This commit is contained in:
parent
48736417d6
commit
030b96edad
|
@ -21,16 +21,25 @@ const App = () => {
|
|||
]
|
||||
|
||||
const [selected, setSelected] = useState(0)
|
||||
const [scores, setScores] = useState(Array(anecdotes.length).fill(0))
|
||||
|
||||
const randomText = () => {
|
||||
const value = Math.floor(Math.random() * anecdotes.length)
|
||||
setSelected(value)
|
||||
}
|
||||
|
||||
const VoteUp = () => {
|
||||
const copy = [...scores]
|
||||
copy[selected] += 1
|
||||
setScores(copy)
|
||||
}
|
||||
|
||||
return (
|
||||
<div>
|
||||
<Button handler={randomText} text="Randomize" />
|
||||
{anecdotes[selected]}
|
||||
<Button handler={VoteUp} text="Vote" />
|
||||
<p>{anecdotes[selected]}</p>
|
||||
<p>Votes: {scores[selected]}</p>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue