From 030b96edad309a6d8f80c7f8c01fca72750a9e65 Mon Sep 17 00:00:00 2001 From: Anish Lakhwara Date: Mon, 15 May 2023 22:12:23 +1000 Subject: [PATCH] exercise 1.13 --- part1/src/App.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) 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 (
) }