From 2850cda94b96ae0eff65aa4c00cf1786ff772ffa Mon Sep 17 00:00:00 2001 From: Anish Lakhwara Date: Mon, 15 May 2023 23:47:23 +1000 Subject: [PATCH] exercise 2.4 --- part2/src/App.js | 85 ++++++++++++++++++++++++++++++------------------ 1 file changed, 53 insertions(+), 32 deletions(-) diff --git a/part2/src/App.js b/part2/src/App.js index 92f12e1..54b6632 100644 --- a/part2/src/App.js +++ b/part2/src/App.js @@ -15,53 +15,74 @@ const Content = ({ parts }) => { } const Sum = ({ parts }) => { - // Already used reduce :3 const total = parts.reduce((acc, currVal) => acc + currVal.exercises, 0) return ( The total number of execrcises is {total} ) } -const Course = ({ course }) => { +const Course = ({ courses }) => { return ( <> -
- - + {courses.map(course => + <> +
+ + + + )} ) } function App() { - const course = { - id: 1, - name: 'Half Stack application development', - parts: [ - { - name: 'Fundamentals of React', - exercises: 10, - id: 1 - }, - { - name: 'Using props to pass data', - exercises: 7, - id: 2 - }, - { - name: 'State of a component', - exercises: 14, - id: 3 - }, - { - name: 'Redux', - exercises: 11, - id: 4 - } - ] - } + const courses = [ + { + name: 'Half Stack application development', + id: 1, + parts: [ + { + name: 'Fundamentals of React', + exercises: 10, + id: 1 + }, + { + name: 'Using props to pass data', + exercises: 7, + id: 2 + }, + { + name: 'State of a component', + exercises: 14, + id: 3 + }, + { + name: 'Redux', + exercises: 11, + id: 4 + } + ] + }, + { + name: 'Node.js', + id: 2, + parts: [ + { + name: 'Routing', + exercises: 3, + id: 1 + }, + { + name: 'Middlewares', + exercises: 7, + id: 2 + } + ] + } + ] - return + return } export default App;