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.4
|
||||||
* [X] 1.5
|
* [X] 1.5
|
||||||
* [X] 1.6
|
* [X] 1.6
|
||||||
* [ ] 1.7
|
* [X] 1.7
|
||||||
* [ ] 1.8
|
* [ ] 1.8
|
||||||
* [ ] 1.9
|
* [ ] 1.9
|
||||||
* [ ] 1.10
|
* [ ] 1.10
|
||||||
|
|
|
||||||
|
|
@ -8,10 +8,10 @@ const Button = (props) => {
|
||||||
return <button onClick={props.onClickCallback}>{props.buttonText} </button>;
|
return <button onClick={props.onClickCallback}>{props.buttonText} </button>;
|
||||||
};
|
};
|
||||||
|
|
||||||
const Counter = (props) => {
|
const StatisticDisplay = (props) => {
|
||||||
return (
|
return (
|
||||||
<p>
|
<p>
|
||||||
{props.counterName} {props.counterValue}
|
{props.statisticName} {props.statisticValue}
|
||||||
</p>
|
</p>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
@ -22,6 +22,16 @@ const App = () => {
|
||||||
const [neutral, setNeutral] = useState(0);
|
const [neutral, setNeutral] = useState(0);
|
||||||
const [bad, setBad] = 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 (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<Header headerText="give feedback" />
|
<Header headerText="give feedback" />
|
||||||
|
|
@ -44,9 +54,21 @@ const App = () => {
|
||||||
buttonText="bad"
|
buttonText="bad"
|
||||||
/>
|
/>
|
||||||
<Header headerText="statistics" />
|
<Header headerText="statistics" />
|
||||||
<Counter counterName="good" counterValue={good} />
|
<StatisticDisplay statisticName="good" statisticValue={good} />
|
||||||
<Counter counterName="neutral" counterValue={neutral} />
|
<StatisticDisplay statisticName="neutral" statisticValue={neutral} />
|
||||||
<Counter counterName="bad" counterValue={bad} />
|
<StatisticDisplay statisticName="bad" statisticValue={bad} />
|
||||||
|
<StatisticDisplay
|
||||||
|
statisticName="count"
|
||||||
|
statisticValue={computeTotalCount()}
|
||||||
|
/>
|
||||||
|
<StatisticDisplay
|
||||||
|
statisticName="average"
|
||||||
|
statisticValue={computeAverage()}
|
||||||
|
/>
|
||||||
|
<StatisticDisplay
|
||||||
|
statisticName="positive"
|
||||||
|
statisticValue={computePercentagePositive() * 100 + "%"}
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
// Buttons
|
// Buttons
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue