mirror of
https://github.com/10h30/fullstackopen.git
synced 2026-06-05 15:08:33 +09:00
Completed 1.8 (unicafe step 3)
This commit is contained in:
@@ -6,23 +6,36 @@ const App = () => {
|
||||
const [neutral, setNeutral] = useState(0)
|
||||
const [bad, setBad] = useState(0)
|
||||
|
||||
const all = good + bad + neutral
|
||||
const avg = (all !== 0) ? (good - bad) / all : 0
|
||||
const positive = (all !== 0) ? good/all*100 : "NA"
|
||||
|
||||
const Statistics = (props) => {
|
||||
const [good, neutral, bad] = props.data
|
||||
const all = good + bad + neutral
|
||||
const avg = (all !== 0) ? (good - bad) / all : 0
|
||||
const positive = (all !== 0) ? good/all*100 : "NA"
|
||||
|
||||
return (
|
||||
<div>
|
||||
<h1>Statistic</h1>
|
||||
<p>Good: {good}</p>
|
||||
<p>Neutral: {neutral}</p>
|
||||
<p>Bad: {bad}</p>
|
||||
<p>All: {all}</p>
|
||||
<p>Average: {avg} </p>
|
||||
<p>Positive: {positive} %</p>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
return (
|
||||
<div>
|
||||
<h1>Give feedback</h1>
|
||||
|
||||
<button onClick={() => setGood(good + 1)}>good</button>
|
||||
<button onClick={() => setNeutral(neutral + 1)}>neutral</button>
|
||||
<button onClick={() => setBad(bad + 1)}>bad</button>
|
||||
<h1>Statistic</h1>
|
||||
<p>Good: {good}</p>
|
||||
<p>Neutral: {neutral}</p>
|
||||
<p>Bad: {bad}</p>
|
||||
<p>All: {all}</p>
|
||||
<p>Average: {avg} </p>
|
||||
<p>Positive: {positive} %</p>
|
||||
|
||||
<Statistics data={[good, neutral, bad]}/>
|
||||
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user