Skip to content

Commit 45d7d2f

Browse files
authored
Merge pull request #11 from mahmudul-Hasan-2/week-2-readme
Week-2 challenge readme updated
2 parents 848b8ca + 4b8aea9 commit 45d7d2f

2 files changed

Lines changed: 61 additions & 0 deletions

File tree

challenges/week-2.md

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# Week 2 challenge - Simple Counter App
2+
3+
## Objective
4+
5+
Create a counter app there you will show three button : Increase, Decrease, Reset and Show The count over the buttons.
6+
7+
## Requirements
8+
9+
- Create a `Counter` Component.
10+
- Declare a state name of count and setCount.
11+
- Make three buttons : Increase, Decrease, Reset and give them event handler by function like: function handleIncrement and handleDecrement and handleReset.
12+
- If someone click on increase button the count will be increase and If someone click on decrease button the count will be decrease before going to 0 and If someone click on reset button the count will be 0 before going to 0.
13+
- Display: `0` initially;
14+
15+
## Submission
16+
17+
- Branch: `week-2-solution`
18+
- Submit PR to this repository
19+
- Include your GitHub username in the PR title
20+
21+
## Points
22+
23+
- Challenge completed: 15 points
24+
- PR merged: 10 points
25+
26+
---
27+
28+
### Solution by @mahmudul-Hasan-2
29+
30+
```javascript
31+
import React from "react";
32+
33+
function Greeting() {
34+
const [count, setCount] = useState(0);
35+
function handleIncrement () {
36+
setCount(count + 1);
37+
}
38+
function handleDecrement () {
39+
count > 0 && setCount(count - 1);
40+
}
41+
function handleReset () {
42+
count > 0 setCount(0);
43+
}
44+
return (
45+
<div>
46+
<h2>{count}</h2>
47+
<button onClick={handleIncrement}>Increment</button>
48+
<button onClick={handleDecrement}>Decrement</button>
49+
<button onClick={handleReset}>Reset</button>
50+
</div>
51+
)
52+
}
53+
54+
export default Greeting;
55+
```

package-lock.json

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)