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

Exercise 1.7

parent 9e33b90a
No related branches found
No related tags found
No related merge requests found
...@@ -21,6 +21,23 @@ class App extends React.Component { ...@@ -21,6 +21,23 @@ class App extends React.Component {
return () => {this.setState({ bad: this.state.bad + 1 })} return () => {this.setState({ bad: this.state.bad + 1 })}
} }
} }
const mean = () => {
if (this.state.good === 0 && this.state.neutral === 0 && this.state.bad === 0) {
return 0
} else {
return (
(this.state.good - this.state.bad) / (this.state.good + this.state.neutral + this.state.bad)
)
}
}
const positivePercentage = () => {
if (this.state.good === 0) {
return 0
} else {
return this.state.good / (this.state.good + this.state.neutral + this.state.bad)
}
}
return ( return (
<div> <div>
<h2>anna palautetta</h2> <h2>anna palautetta</h2>
...@@ -32,6 +49,8 @@ class App extends React.Component { ...@@ -32,6 +49,8 @@ class App extends React.Component {
<p>Hyvä: {this.state.good}</p> <p>Hyvä: {this.state.good}</p>
<p>Neutraali: {this.state.neutral}</p> <p>Neutraali: {this.state.neutral}</p>
<p>Huono: {this.state.bad}</p> <p>Huono: {this.state.bad}</p>
<p>Keskiarvo: {mean()} </p>
<p>Positiivisia: {positivePercentage()}%</p>
</div> </div>
) )
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment