diff --git a/part1/src/App.js b/part1/src/App.js index 16be05a..e1d953b 100644 --- a/part1/src/App.js +++ b/part1/src/App.js @@ -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 (
{anecdotes[selected]}
+Votes: {scores[selected]}