exercise 2.5
This commit is contained in:
parent
2850cda94b
commit
bdc6551783
|
@ -1,40 +1,4 @@
|
|||
const Header = ({ content }) => {
|
||||
return (<h1>{content}</h1>)
|
||||
}
|
||||
|
||||
const Content = ({ parts }) => {
|
||||
return (
|
||||
<>
|
||||
{parts.map(part =>
|
||||
<p key={part.id}>
|
||||
{part.name} Exercises {part.exercises}
|
||||
</p>)
|
||||
}
|
||||
</>
|
||||
)
|
||||
}
|
||||
|
||||
const Sum = ({ parts }) => {
|
||||
const total = parts.reduce((acc, currVal) => acc + currVal.exercises, 0)
|
||||
return (
|
||||
<b>The total number of execrcises is {total}</b>
|
||||
)
|
||||
}
|
||||
|
||||
const Course = ({ courses }) => {
|
||||
return (
|
||||
<>
|
||||
{courses.map(course =>
|
||||
<>
|
||||
<Header content={course.name} />
|
||||
<Content parts={course.parts} />
|
||||
<Sum parts={course.parts} />
|
||||
</>
|
||||
)}
|
||||
</>
|
||||
)
|
||||
|
||||
}
|
||||
import Course from './components/Course'
|
||||
|
||||
function App() {
|
||||
const courses = [
|
||||
|
|
14
part2/src/components/Content.js
Normal file
14
part2/src/components/Content.js
Normal file
|
@ -0,0 +1,14 @@
|
|||
const Content = ({ parts }) => {
|
||||
return (
|
||||
<>
|
||||
{parts.map(part =>
|
||||
<p key={part.id}>
|
||||
{part.name} Exercises {part.exercises}
|
||||
</p>)
|
||||
}
|
||||
</>
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
export default Content;
|
19
part2/src/components/Course.js
Normal file
19
part2/src/components/Course.js
Normal file
|
@ -0,0 +1,19 @@
|
|||
import Content from './Content'
|
||||
import Header from './Header'
|
||||
import Sum from './Sum'
|
||||
|
||||
const Course = ({ courses }) => {
|
||||
return (
|
||||
<>
|
||||
{courses.map(course =>
|
||||
<>
|
||||
<Header content={course.name} />
|
||||
<Content parts={course.parts} />
|
||||
<Sum parts={course.parts} />
|
||||
</>
|
||||
)}
|
||||
</>
|
||||
)
|
||||
}
|
||||
|
||||
export default Course;
|
5
part2/src/components/Header.js
Normal file
5
part2/src/components/Header.js
Normal file
|
@ -0,0 +1,5 @@
|
|||
const Header = ({ content }) => {
|
||||
return (<h1>{content}</h1>)
|
||||
}
|
||||
|
||||
export default Header;
|
8
part2/src/components/Sum.js
Normal file
8
part2/src/components/Sum.js
Normal file
|
@ -0,0 +1,8 @@
|
|||
const Sum = ({ parts }) => {
|
||||
const total = parts.reduce((acc, currVal) => acc + currVal.exercises, 0)
|
||||
return (
|
||||
<b>The total number of execrcises is {total}</b>
|
||||
)
|
||||
}
|
||||
|
||||
export default Sum;
|
Loading…
Reference in a new issue