compelted 1.14
This commit is contained in:
parent
53abf66608
commit
f741853323
2 changed files with 17 additions and 1 deletions
|
|
@ -30,11 +30,27 @@ const App = (props) => {
|
|||
setSelected(Math.floor(Math.random() * props.anecdotes.length))
|
||||
}
|
||||
|
||||
const getMostVotedIndex = (votesArray) => {
|
||||
let highestVoteCount = 0;
|
||||
let highestVoteIndex;
|
||||
for (let i = 0; i < votesArray.length; i++) {
|
||||
if (votesArray[i] >= highestVoteCount) {
|
||||
highestVoteIndex = i
|
||||
highestVoteCount = votesArray[i]
|
||||
}
|
||||
}
|
||||
|
||||
return highestVoteIndex;
|
||||
}
|
||||
|
||||
return (
|
||||
<>
|
||||
<AnecdoteDisplay anecdotes={props.anecdotes} anecdoteIndex={selected} anecdoteVotes={votes[selected]}/>
|
||||
<Button buttonText={'Vote this'} onClickCallback={voteQuote}/>
|
||||
<Button buttonText={'Next'} onClickCallback={selectRandomAnecdote}/>
|
||||
|
||||
<h1>The most popular anecdote</h1>
|
||||
<AnecdoteDisplay anecdotes={props.anecdotes} anecdoteIndex={getMostVotedIndex(votes)} anecdoteVotes={votes[getMostVotedIndex(votes)]}/>
|
||||
</>
|
||||
)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ Exercises:
|
|||
* [X] 1.11
|
||||
* [X] 1.12
|
||||
* [X] 1.13
|
||||
* [ ] 1.14
|
||||
* [X] 1.14
|
||||
|
||||
My own final exercise:
|
||||
* Make a website for which you give a principal and an interest rate, and it computes the monthly installments and gives you the breakdown of interest and amortization you will pay each month.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue