Finalize 1.11
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
import { useState } from "react";
|
import { useState } from "react";
|
||||||
const Button = (props) => {
|
const Button = ({ handleClick, text }) => {
|
||||||
return <button onClick={props.handleClick}>{props.text}</button>;
|
return <button onClick={handleClick}>{text}</button>;
|
||||||
};
|
};
|
||||||
// StatistticsLine should display as a HTML table
|
// StatistticsLine should display as a HTML table
|
||||||
const StatisticsLine = ({ text, value }) => {
|
const StatisticsLine = ({ text, value }) => {
|
||||||
@@ -11,30 +11,23 @@ const StatisticsLine = ({ text, value }) => {
|
|||||||
</tr>
|
</tr>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
const Statistics = (props) => {
|
const Statistics = ({ good, neutral, bad }) => {
|
||||||
if (props.good + props.neutral + props.bad === 0) {
|
if (good + neutral + bad === 0 || !(good || neutral || bad)) {
|
||||||
return <p>No feedback given</p>;
|
return <p>No feedback given</p>;
|
||||||
} else {
|
} else {
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<StatisticsLine text="good" value={props.good} />
|
<StatisticsLine text="good" value={good} />
|
||||||
<StatisticsLine text="neutral" value={props.neutral} />
|
<StatisticsLine text="neutral" value={neutral} />
|
||||||
<StatisticsLine text="bad" value={props.bad} />
|
<StatisticsLine text="bad" value={bad} />
|
||||||
<StatisticsLine
|
<StatisticsLine text="all" value={good + neutral + bad} />
|
||||||
text="all"
|
|
||||||
value={props.good + props.neutral + props.bad}
|
|
||||||
/>
|
|
||||||
<StatisticsLine
|
<StatisticsLine
|
||||||
text="average"
|
text="average"
|
||||||
value={
|
value={(good - bad) / (good + neutral + bad)}
|
||||||
(props.good - props.bad) / (props.good + props.neutral + props.bad)
|
|
||||||
}
|
|
||||||
/>
|
/>
|
||||||
<StatisticsLine
|
<StatisticsLine
|
||||||
text="positive"
|
text="positive"
|
||||||
value={
|
value={(good / (good + neutral + bad)) * 100 + " %"}
|
||||||
(props.good / (props.good + props.neutral + props.bad)) * 100 + "%"
|
|
||||||
}
|
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user