completed exercise 1.7
This commit is contained in:
parent
14fbf0aa7c
commit
f9bfc61e6c
2 changed files with 28 additions and 6 deletions
|
|
@ -8,7 +8,7 @@ Exercises:
|
|||
* [X] 1.4
|
||||
* [X] 1.5
|
||||
* [X] 1.6
|
||||
* [ ] 1.7
|
||||
* [X] 1.7
|
||||
* [ ] 1.8
|
||||
* [ ] 1.9
|
||||
* [ ] 1.10
|
||||
|
|
|
|||
|
|
@ -8,10 +8,10 @@ const Button = (props) => {
|
|||
return <button onClick={props.onClickCallback}>{props.buttonText} </button>;
|
||||
};
|
||||
|
||||
const Counter = (props) => {
|
||||
const StatisticDisplay = (props) => {
|
||||
return (
|
||||
<p>
|
||||
{props.counterName} {props.counterValue}
|
||||
{props.statisticName} {props.statisticValue}
|
||||
</p>
|
||||
);
|
||||
};
|
||||
|
|
@ -22,6 +22,16 @@ const App = () => {
|
|||
const [neutral, setNeutral] = useState(0);
|
||||
const [bad, setBad] = useState(0);
|
||||
|
||||
const computeTotalCount = () => {
|
||||
return good + neutral + bad;
|
||||
};
|
||||
const computeAverage = () => {
|
||||
return (good - bad) / computeTotalCount();
|
||||
};
|
||||
const computePercentagePositive = () => {
|
||||
return good / computeTotalCount();
|
||||
};
|
||||
|
||||
return (
|
||||
<div>
|
||||
<Header headerText="give feedback" />
|
||||
|
|
@ -44,9 +54,21 @@ const App = () => {
|
|||
buttonText="bad"
|
||||
/>
|
||||
<Header headerText="statistics" />
|
||||
<Counter counterName="good" counterValue={good} />
|
||||
<Counter counterName="neutral" counterValue={neutral} />
|
||||
<Counter counterName="bad" counterValue={bad} />
|
||||
<StatisticDisplay statisticName="good" statisticValue={good} />
|
||||
<StatisticDisplay statisticName="neutral" statisticValue={neutral} />
|
||||
<StatisticDisplay statisticName="bad" statisticValue={bad} />
|
||||
<StatisticDisplay
|
||||
statisticName="count"
|
||||
statisticValue={computeTotalCount()}
|
||||
/>
|
||||
<StatisticDisplay
|
||||
statisticName="average"
|
||||
statisticValue={computeAverage()}
|
||||
/>
|
||||
<StatisticDisplay
|
||||
statisticName="positive"
|
||||
statisticValue={computePercentagePositive() * 100 + "%"}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
// Buttons
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue