completed 1.14 (anecdotes step 3)

This commit is contained in:
2021-08-26 22:23:26 +07:00
parent 817eb41083
commit b58d937215
+5 -5
View File
@@ -30,15 +30,16 @@ const App = () => {
setPoints(newpoints) setPoints(newpoints)
} }
const Best = (props) => { const BestNote = (props) => {
const best = props.data const best = props.data
const mostvote = Math.max(...best) const mostvote = Math.max(...best)
const index = best.indexOf(mostvote); const index = best.indexOf(mostvote);
return ( return (
<div> <div>
<h2>Anecdote with most votes</h2> <h2>Anecdote with most votes</h2>
<p>{props.notes[index]}</p> {mostvote >0 && <div><p>{props.notes[index]}</p>
<span>has {mostvote} votes</span> <span>has {mostvote} votes</span></div>}
</div> </div>
) )
} }
@@ -51,8 +52,7 @@ const App = () => {
<button onClick={setVote}>vote</button><button onClick={setRandom}>Next Anecdote</button> <button onClick={setVote}>vote</button><button onClick={setRandom}>Next Anecdote</button>
</div> </div>
<Best data={points} notes={anecdotes}/> <BestNote data={points} notes={anecdotes}/>
</div> </div>
) )