From cd2ce52190a8bb33323fee3b20adcbb1faf032a8 Mon Sep 17 00:00:00 2001 From: Ibrahim Mkusa Date: Sun, 23 Apr 2023 19:39:26 -0400 Subject: ex 1.4 --- part1/courseinfo/src/App.js | 53 ++++++++++++++++++++++++++------------------- 1 file changed, 31 insertions(+), 22 deletions(-) diff --git a/part1/courseinfo/src/App.js b/part1/courseinfo/src/App.js index 70f0e8b..a500c35 100644 --- a/part1/courseinfo/src/App.js +++ b/part1/courseinfo/src/App.js @@ -4,45 +4,54 @@ const Header = (props) => { ) } -const Part = (props) => { -//// props.part is an object containing name and exercises +const Content = (props) => { + const object_1 = props.parts[0] + const object_2 = props.parts[1] + const object_3 = props.parts[2] + return (

- {props.part.name} {props.part.exercises} + {object_1.name} {object_1.exercises} +
+ {object_2.name} {object_2.exercises} +
+ {object_3.name} {object_3.exercises}

) } const Total = (props) => { + const one = props.parts[0].exercises + const two = props.parts[1].exercises + const three = props.parts[2].exercises + return ( -

Number of exercises {props.one + props.two + props.three}

+

Number of exercises {one + two + three}

) } const App = () => { const course = 'Half Stack application development' - const part1 = { - name: 'Fundamentals of React', - exercises: 10 - } - - const part2 = { - name: 'Using props to pass data', - exercises: 7 - } - - const part3 = { - name: 'State of a component', - exercises: 14 - } + const parts = [ + { + name: 'Fundamentals of React', + exercises: 10 + }, + { + name: 'Using props to pass data', + exercises: 7 + }, + { + name: 'State of a component', + exercises: 14 + } + ] return (
- - - - + +
) } -- cgit v1.2.3