Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added counter #369

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 1 addition & 15 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,3 @@
# React counter

> Here is [the working version](https://mate-academy.github.io/react_counter/)

You have the `App` with a title and 3 buttons. Implement `addOne` and `add100` functions so the buttons work the next way:

- `Add 1` button calls `addOne` method to add `1` to the `count`;
- `Add 100` button calls `add100` method to add `100` to the `count`;
- `Increase` button calls `addOne` and then, if count was divisible by 5, it additionally calls `add100`.

So the third button should count like this:
`101, 102, 103, 104, 105, 206, 207, 208, 209, 210, 311 ...`

## Instructions
- Implement a solution following the [React task guideline](https://github.com/mate-academy/react_task-guideline#react-tasks-guideline).
- Open one more terminal and run tests with `npm test` to ensure your solution is correct.
- Replace `<your_account>` with your Github username in the [DEMO LINK](https://<your_account>.github.io/react_counter-js/) and add it to PR description.
> Here is [the working version](https://ionshive.github.io/react_counter/)
19 changes: 9 additions & 10 deletions src/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,39 +2,38 @@ import { useState } from 'react';
import './App.scss';

export const App = () => {
const [count] = useState(0);
const [count, setCount] = useState(0);

const addOne = () => {
// write code here
setCount(count + 1);
};

const add100 = () => {
// write code here
setCount(count + 100);
};

// DON'T change the code below
const increase = () => {
if (count % 5 === 0) {
add100();
}
setCount((currentCount) => {
if (currentCount % 5 === 0) {
return currentCount + 100 + 1;
}

addOne();
return currentCount + 1;
});
};

return (
<div className="App">
<h1 className="App__title">
{`Count: ${count}`}
</h1>

<button type="button" className="App__add-one" onClick={addOne}>
Add 1
</button>

<button type="button" className="App__add-100" onClick={add100}>
Add 100
</button>

<button type="button" className="App__increase" onClick={increase}>
Increase
</button>
Expand Down
Loading