diff --git a/part1/1.12-1.14-anecdotes/src/App.js b/part1/1.12-1.14-anecdotes/src/App.js index a0a9eb1..9b32e72 100644 --- a/part1/1.12-1.14-anecdotes/src/App.js +++ b/part1/1.12-1.14-anecdotes/src/App.js @@ -12,6 +12,8 @@ const App = () => { ] const [selected, setSelected] = useState(0) + const [points, setPoints] = useState(Array(anecdotes.length).fill(0)) + const setRandom = () => { const min = 0 const max = anecdotes.length-1 @@ -19,10 +21,19 @@ const App = () => { console.log(random) setSelected(random) } + + const setVote = () => { + const newpoints = {...points} + newpoints[selected] += 1 + setPoints(newpoints) + console.log(points) + } + return (

{anecdotes[selected]}

- +

has {points[selected]} votes

+
) }