From bdc6551783d408fb961a63e27abdd473fc821021 Mon Sep 17 00:00:00 2001 From: Anish Lakhwara Date: Tue, 16 May 2023 00:15:43 +1000 Subject: [PATCH] exercise 2.5 --- part2/src/App.js | 38 +-------------------------------- part2/src/components/Content.js | 14 ++++++++++++ part2/src/components/Course.js | 19 +++++++++++++++++ part2/src/components/Header.js | 5 +++++ part2/src/components/Sum.js | 8 +++++++ 5 files changed, 47 insertions(+), 37 deletions(-) create mode 100644 part2/src/components/Content.js create mode 100644 part2/src/components/Course.js create mode 100644 part2/src/components/Header.js create mode 100644 part2/src/components/Sum.js diff --git a/part2/src/App.js b/part2/src/App.js index 54b6632..e97353f 100644 --- a/part2/src/App.js +++ b/part2/src/App.js @@ -1,40 +1,4 @@ -const Header = ({ content }) => { - return (

{content}

) -} - -const Content = ({ parts }) => { - return ( - <> - {parts.map(part => -

- {part.name} Exercises {part.exercises} -

) - } - - ) -} - -const Sum = ({ parts }) => { - const total = parts.reduce((acc, currVal) => acc + currVal.exercises, 0) - return ( - The total number of execrcises is {total} - ) -} - -const Course = ({ courses }) => { - return ( - <> - {courses.map(course => - <> -
- - - - )} - - ) - -} +import Course from './components/Course' function App() { const courses = [ diff --git a/part2/src/components/Content.js b/part2/src/components/Content.js new file mode 100644 index 0000000..dbc3d0e --- /dev/null +++ b/part2/src/components/Content.js @@ -0,0 +1,14 @@ +const Content = ({ parts }) => { + return ( + <> + {parts.map(part => +

+ {part.name} Exercises {part.exercises} +

) + } + + ) +} + + +export default Content; diff --git a/part2/src/components/Course.js b/part2/src/components/Course.js new file mode 100644 index 0000000..99914cf --- /dev/null +++ b/part2/src/components/Course.js @@ -0,0 +1,19 @@ +import Content from './Content' +import Header from './Header' +import Sum from './Sum' + +const Course = ({ courses }) => { + return ( + <> + {courses.map(course => + <> +
+ + + + )} + + ) +} + +export default Course; diff --git a/part2/src/components/Header.js b/part2/src/components/Header.js new file mode 100644 index 0000000..9616233 --- /dev/null +++ b/part2/src/components/Header.js @@ -0,0 +1,5 @@ +const Header = ({ content }) => { + return (

{content}

) +} + +export default Header; diff --git a/part2/src/components/Sum.js b/part2/src/components/Sum.js new file mode 100644 index 0000000..87d103e --- /dev/null +++ b/part2/src/components/Sum.js @@ -0,0 +1,8 @@ +const Sum = ({ parts }) => { + const total = parts.reduce((acc, currVal) => acc + currVal.exercises, 0) + return ( + The total number of execrcises is {total} + ) +} + +export default Sum;