-
Notifications
You must be signed in to change notification settings - Fork 1.7k
resolve #1759
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
base: master
Are you sure you want to change the base?
resolve #1759
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Review Summary
I’m requesting changes because two critical requirements are not met and they block correct functionality.
- Initial state: On src/App.jsx line where
useStateis initialized,countstarts at0, but the requirement states the Increase sequence must begin 101, 102, ...; this implies the initialcountmust be100so the first Increase yields101. - Increase logic/order: In src/App.jsx, the
increasehandler checkscount % 5 === 0before callingaddOne()and may calladd100()using stale state. The requirement is: first calladdOneto add 1; then, based on the updated count, if it’s divisible by 5, calladd100. This must avoid stale state by either computingnewCount = count + 1and checkingnewCount % 5 === 0, or by using a functional updater and performing the divisibility check on the updated value.
What you did well: UI structure, addOne and add100 use functional updaters and are correctly wired to their buttons.
Minor: Keep the code simple and avoid unnecessary checks; comments can note the required Increase sequence.
Please update the initial state to 100 and fix the Increase handler’s order/check so tests for the sequence (101, 102, 103, 104, 105, 206, …) pass. Keep going—you’re close!
✨ Please rate this review in the Platform's notification center1. I will be grateful for your feedback! ✨
Important
Fix the issues, commit the changes, and then re-request my review using the Re-request review button2 in the Reviewers tab.
Tip
If you have any comments about this review, please leave a message in the Add a comment section below and mention me with the @mateacademy-ai-mentor tag3.
I will read your message during my next review of your pull request. Please do not reply directly to my comments, as that feature is not supported yet.
Caution
Do not close the pull request until the review is complete. Closing it early can lead to unexpected behavior and disrupt the review process.
Footnotes
|
|
||
| export const App = () => { | ||
| const [count] = useState(0); | ||
| const [count, setCount] = useState(0); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This violates the checklist requirement: "The sequence of values produced by repeatedly clicking "Increase" must match: 101, 102, 103, 104, 105, 206, 207, 208, 209, 210, 311, ..." — the initial state is 0 here, so the first Increase cannot produce 101. Set the initial count to 100 instead of 0 so the sequence starts at 101.
| // eslint-disable-next-line no-shadow | ||
| setCount(count => { | ||
| return count + 1; | ||
| }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This violates the checklist requirement: "The 'Increase' button must: Call addOne to increase the count by 1. After that, if the resulting count is divisible by 5, additionally call add100 to increase the count by 100 more." The current increase implementation checks count % 5 === 0 before calling addOne() and may call add100() using stale state and in the wrong order. Change the logic so the +1 is applied first and the divisibility check is performed on the updated value (use a functional updater to avoid stale state or restructure so the check runs after the +1).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Review Summary
I’m requesting changes because two critical requirements are not met, which will break the expected Increase sequence and likely fail tests.
- Issue 1 (src/App.jsx line where state is initialized):
useState(0)starts at 0, but the spec requires the first Increase to produce 101. Initialize withuseState(100)so the first press yields 101. - Issue 2 (src/App.jsx in the
increasehandler): The logic checks divisibility before adding 1, which violates the requirement “add 1, then if the updated value is divisible by 5, add 100.” Fix by first computing the next value (e.g.,const next = count + 1), applyingaddOne(), and then conditionally applyingadd100()ifnext % 5 === 0. Alternatively, use a single functionalsetCount(prev => { const next = prev + 1; return next % 5 === 0 ? next + 100 : next; }).
What’s good: addOne and add100 are correctly implemented and the UI wiring looks correct. After making these two fixes, the Increase sequence should be 101, 102, 103, 104, 105, 206, 207, … and tests should pass. Keep up the good work—these are targeted changes to align with the spec.
✨ Please rate this review in the Platform's notification center1. I will be grateful for your feedback! ✨
Important
Fix the issues, commit the changes, and then re-request my review using the Re-request review button2 in the Reviewers tab.
Tip
If you have any comments about this review, please leave a message in the Add a comment section below and mention me with the @mateacademy-ai-mentor tag3.
I will read your message during my next review of your pull request. Please do not reply directly to my comments, as that feature is not supported yet.
Caution
Do not close the pull request until the review is complete. Closing it early can lead to unexpected behavior and disrupt the review process.
Footnotes
|
|
||
| export const App = () => { | ||
| const [count] = useState(0); | ||
| const [count, setCount] = useState(0); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This violates the requirement that the first Increase should produce 101. The description expects the Increase sequence: "So the third button should count like this: 101, 102, 103, 104, 105, 206, 207, ..." Currently useState is initialized to 0. Initialize the state to 100 (e.g. useState(100)) so the first Increase yields 101 as required.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Review Summary
Here is my approval to help you progress while learning. You set up the React component cleanly with clear handlers and proper button wiring—nice job using functional updates for addOne and add100.
However, two critical fixes are needed for the Increase behavior:
- In src/App.jsx, initialize the state to 100 (e.g.,
useState(100)) so the first Increase press yields 101 as required. - In src/App.jsx, the
increasehandler currently checkscount % 5 === 0using the old value. The requirement says: first add 1, then if the updated value is divisible by 5, add 100. Use a single functional update that computesnext = prev + 1and then conditionally adds 100 based onnext % 5 === 0to avoid stale state.
These changes will produce the correct sequence: 101, 102, 103, 104, 105, 206, ... Keep going—you’re very close!
✨ Please rate this review in the Platform's notification center1. I will be grateful for your feedback! ✨
Footnotes
|
|
||
| export const App = () => { | ||
| const [count] = useState(0); | ||
| const [count, setCount] = useState(0); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This violates the requirement that the first Increase press results in 101. Initialize the counter to 100 (e.g., useState(100)) so the first Increase yields 101. Requirement: "The Increase button must produce the sequence: 101, 102, 103, 104, 105, 206, ..."
| addOne(); | ||
|
|
||
| if (count % 5 === 0) { | ||
| add100(); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The increase handler calls addOne() and then checks if (count % 5 === 0), which tests the old value (count) instead of the updated value. This violates: "It first adds 1... After adding 1, if the updated count is divisible by 5, it additionally adds 100." Use a single functional update to avoid stale state, for example: setCount(prev => { const next = prev + 1; return next % 5 === 0 ? next + 100 : next; }) so the divisibility check uses the new value.
No description provided.