Completed 1.10 (unicafe step 5)

This commit is contained in:
2021-08-26 20:34:41 +07:00
parent b510a037b2
commit 7e9b95c8a3
+19 -11
View File
@@ -11,7 +11,7 @@ const App = () => {
const [good, neutral, bad] = props.data const [good, neutral, bad] = props.data
const all = good + bad + neutral const all = good + bad + neutral
const avg = (all !== 0) ? (good - bad) / all : 0 const avg = (all !== 0) ? (good - bad) / all : 0
const positive = (all !== 0) ? good/all*100 : "NA" const positive = (all !== 0) ? good/all*100 + " %": "NA"
return ( return (
@@ -19,12 +19,13 @@ const App = () => {
<h1>Statistic</h1> <h1>Statistic</h1>
{all > 0 && {all > 0 &&
<div> <div>
<p>Good: {good}</p> <StatisticLine text="Good" value ={good} />
<p>Neutral: {neutral}</p> <StatisticLine text="Neutral" value ={neutral} />
<p>Bad: {bad}</p> <StatisticLine text="Bad" value ={bad} />
<p>All: {all}</p> <StatisticLine text="All" value ={all} />
<p>Average: {avg} </p> <StatisticLine text="Average" value ={avg} />
<p>Positive: {positive} %</p> <StatisticLine text="Positive" value ={positive} />
</div> </div>
} }
{all === 0 && "No feedback given"} {all === 0 && "No feedback given"}
@@ -32,13 +33,20 @@ const App = () => {
) )
} }
const StatisticLine = (props) => <p>{props.text}: {props.value}</p>
const Button = (props) => {
return (
<button onClick={props.onClick}>{props.text}</button>
)
}
return ( return (
<div> <div>
<h1>Give feedback</h1> <h1>Give feedback</h1>
<Button text="good" onClick={() => setGood(good + 1)} />
<button onClick={() => setGood(good + 1)}>good</button> <Button text="neutral" onClick={() => setNeutral(neutral + 1)} />
<button onClick={() => setNeutral(neutral + 1)}>neutral</button> <Button text="bad" onClick={() => setBad(bad + 1)} />
<button onClick={() => setBad(bad + 1)}>bad</button>
<Statistics data={[good, neutral, bad]}/> <Statistics data={[good, neutral, bad]}/>