-
Notifications
You must be signed in to change notification settings - Fork 0
/
App.jsx
81 lines (71 loc) · 2.39 KB
/
App.jsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
const App = () => { //" App" is always our primary component.
const course = { // This is an object named "course"
name: 'Half Stack application development', // This is the first property of the object.
parts: [ // Similarly, an array property.
{
name: 'Fundamentals of React',
exercises1: 10
},
{
name: 'Using props to pass data',
exercises2: 7
},
{
name: 'State of a Component',
exercises3: 14
}
]
}
return ( // Here, we will be calling the components that have been created to serve our purpose.
<div>
<Header course={course.name}/>
<Content parts={course.parts}/>
<Total parts={course.parts}/>
</div>
)
}
// For printing the name of the course.
const Header = ({course}) => { // "course.name" has been passed to "course", both in parentheses(unlike other programming languages) as we need the value stored inside the variables,
console.log(course) // This prints the value of course on the console tab.
return(
<div>
<p>{course}</p>
</div>
)
}
// For printing the name of the specific part and the number of exercises in there.
const Content = ({parts}) => {
console.log(parts)
return( // The "Part" component has been called 3 times for 3 parts. This means that the component prints one part's details at a time.
<div>
<p>
<Part part={parts[0].name} exercise={parts[0].exercises1}/>
<Part part={parts[1].name} exercise={parts[1].exercises2}/>
<Part part={parts[2].name} exercise={parts[2].exercises3}/>
</p>
</div>
)
}
// For printing the name and number of exercises one by one.
const Part = ({part, exercise}) => {
console.log(part, exercise)
return(
<div>
<p>
{part} {exercise}
</p>
</div>
)
}
// For printing the total number of exercises in this course.
const Total = ({parts}) => {
console.log(parts)
return( // A little bit of maths done on the exercises passed and the sum is printed. Pretty simple.😉
<div>
<p>
Number of exercises {parts[0].exercises1+parts[1].exercises2+parts[2].exercises3}
</p>
</div>
)
}
export default App