From a62d2f712a52851c9e33c89c05dc148d2fd1d9a7 Mon Sep 17 00:00:00 2001 From: Anish Lakhwara Date: Mon, 15 May 2023 21:32:23 +1000 Subject: [PATCH] exercise 1.10 --- part1/src/App.js | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/part1/src/App.js b/part1/src/App.js index 629ac91..d7a2aa7 100644 --- a/part1/src/App.js +++ b/part1/src/App.js @@ -1,9 +1,16 @@ import { useState } from 'react' -const Stats = ({ positive, neutral, negative }) => { - const total = positive - negative - const votes = positive + neutral + negative - if (votes == 0) { +const StatisticLine = ({ value, text }) => { + return ( + + {text} + {value} + + ) +} + +const Stats = ({ positive, neutral, negative, total, votes }) => { + if (votes === 0) { return ( <>

No Votes Cast Yet

@@ -13,12 +20,12 @@ const Stats = ({ positive, neutral, negative }) => { return ( <>

Results

-

Positive: {positive}

-

Neutral: {neutral}

-

Negative: {negative}

-

All: {votes}

-

Average: {total / votes}

-

Positive: {positive / votes}

+ + + + + + ) } @@ -35,6 +42,8 @@ const App = () => { const [good, setGood] = useState(0) const [neutral, setNeutral] = useState(0) const [bad, setBad] = useState(0) + const total = good - bad + const votes = good + neutral + bad const incPositive = () => { setGood(good + 1) @@ -54,7 +63,7 @@ const App = () => {