Skip to content
Snippets Groups Projects
Commit 1ae6667b authored by Roy Grönroos's avatar Roy Grönroos
Browse files

Exercise 1.9

parent a794c62b
Branches
No related tags found
No related merge requests found
......@@ -20,22 +20,12 @@ class App extends React.Component {
return () => {this.setState({ bad: this.state.bad + 1 })}
}
}
mean = () => {
if (this.state.good === 0 && this.state.neutral === 0 && this.state.bad === 0) {
return 0
} else {
return (
mean = () => (
(this.state.good - this.state.bad) / (this.state.good + this.state.neutral + this.state.bad)
)
}
}
positivePercentage = () => {
if (this.state.good === 0) {
return 0
} else {
return this.state.good / (this.state.good + this.state.neutral + this.state.bad)
}
}
positivePercentage = () => (
this.state.good / (this.state.good + this.state.neutral + this.state.bad)
)
render() {
return (
<div>
......@@ -59,7 +49,11 @@ const Statistic = ({name, statistic}) => (
<p>{name}: {statistic}</p>
)
const Statistics = ({state, mean, percentage}) => (
const Statistics = ({state, mean, percentage}) => {
if (state.good === 0 && state.neutral === 0 && state.bad === 0) {
return <p>Ei yhtään palautetta annettu.</p>
} else {
return (
<div>
<Statistic name={"Hyvä"} statistic={state.good}/>
<Statistic name={"Neutraali"} statistic={state.neutral}/>
......@@ -68,6 +62,8 @@ const Statistics = ({state, mean, percentage}) => (
<Statistic name={"Positiivisia"} statistic={percentage()}/>
</div>
)
}
}
ReactDOM.render(
<React.StrictMode>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment