remove total, reformat

This commit is contained in:
Pablo Martin 2025-05-20 16:24:28 +02:00
parent ec568c4e9b
commit 1d48e78d7f

View file

@ -1,63 +1,52 @@
const Header = (props) => { const Header = (props) => {
return <h1>{props.course}</h1> return <h1>{props.course}</h1>;
} };
const Part = (props) => { const Part = (props) => {
return <p>{props.partName} {props.exerciseCount}</p> return (
<p>
} {props.partName} {props.exerciseCount}
</p>
);
};
const Content = (props) => { const Content = (props) => {
return ( return (
<> <>
{props.sections.map((section) => { {props.sections.map((section) => {
return <Part partName={section.part} exerciseCount={section.exerciseCount}/> return (
})} <Part partName={section.part} exerciseCount={section.exerciseCount} />
);
})}
</> </>
) );
} };
const Total = (props) => {
return (
<>
<p>Number of exercises {props.sections.reduce(
(sum, section) => {
return sum + section.exerciseCount
},
0
)}</p>
</>
)
}
const App = () => { const App = () => {
const course = { const course = {
name: 'Half Stack application development', name: "Half Stack application development",
sections: [ sections: [
{ {
part: 'Fundamentals of React', part: "Fundamentals of React",
exerciseCount: 10 exerciseCount: 10,
}, },
{ {
part: 'Using props to pass data', part: "Using props to pass data",
exerciseCount: 7 exerciseCount: 7,
}, },
{ {
part: 'State of a component', part: "State of a component",
exerciseCount: 14 exerciseCount: 14,
}, },
],
] };
}
return ( return (
<div> <div>
<Header course={course.name}/> <Header course={course.name} />
<Content sections={course.sections}/> <Content sections={course.sections} />
<Total sections={course.sections}/>
</div> </div>
) );
} };
export default App export default App;