exercise 1.8 and 1.9

This commit is contained in:
counterweight 2025-05-19 23:44:55 +02:00
parent f9bfc61e6c
commit 3fa32ec57c
Signed by: counterweight
GPG key ID: 883EDBAA726BD96C

View file

@ -32,6 +32,39 @@ const App = () => {
return good / computeTotalCount(); return good / computeTotalCount();
}; };
const isThereAnyFeedback = () => {
return computeTotalCount() !== 0;
};
let feedbackSection;
if (isThereAnyFeedback()) {
feedbackSection = (
<>
<StatisticDisplay statisticName="good" statisticValue={good} />
<StatisticDisplay statisticName="neutral" statisticValue={neutral} />
<StatisticDisplay statisticName="bad" statisticValue={bad} />
<StatisticDisplay
statisticName="count"
statisticValue={computeTotalCount()}
/>
<StatisticDisplay
statisticName="average"
statisticValue={computeAverage()}
/>
<StatisticDisplay
statisticName="positive"
statisticValue={computePercentagePositive() * 100 + "%"}
/>
</>
);
} else {
feedbackSection = (
<>
<p>No feedback given.</p>
</>
);
}
return ( return (
<div> <div>
<Header headerText="give feedback" /> <Header headerText="give feedback" />
@ -54,21 +87,7 @@ const App = () => {
buttonText="bad" buttonText="bad"
/> />
<Header headerText="statistics" /> <Header headerText="statistics" />
<StatisticDisplay statisticName="good" statisticValue={good} /> {feedbackSection}
<StatisticDisplay statisticName="neutral" statisticValue={neutral} />
<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