exercise 2.5

This commit is contained in:
Anish Lakhwara 2023-05-16 00:15:43 +10:00
parent 2850cda94b
commit bdc6551783
5 changed files with 47 additions and 37 deletions

View file

@ -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 = [

View 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;

View 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;

View file

@ -0,0 +1,5 @@
const Header = ({ content }) => {
return (<h1>{content}</h1>)
}
export default Header;

View 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;