version 1#1303
Conversation
mateacademy-ai-mentor
left a comment
There was a problem hiding this comment.
Review Summary
I am requesting changes because some behaviors around button initialization and column counting can break the required min/max disabling behavior and may cause tests to fail.
- In
src/scripts/main.js, in the initialization block where you computerowsCountandcolsCount(around the top of the file, near where you query the buttons), you currently only setbtnAppendRow.disabled; instead, call yourupdateButtons()function once there so that all four buttons start in the correct enabled/disabled state according to the current rows/cols (this is essential for the requirement that buttons are disabled at min/max on initial load). - In the row-removal handler in
src/scripts/main.js(where you check whether a row can be removed), you use a DOM length (rows.length) while also trackingrowsCount; to avoid desynchronization between your counter and the DOM, base the condition onrowsCount(e.g.,if (rowsCount > minCount)) and update the DOM androwsCounttogether whenever you add or remove rows. - When you initialize
colsCountfrom the first row (the logic usingfirstRow.querySelectorAll('td')), this will return 0 if the first row uses<th>header cells; change this tofirstRow.querySelectorAll('td, th').lengthso the initialcolsCountcorrectly reflects all visible columns.
As minor improvements, it would also be safer to consistently operate ontbody trrather than alltrelements (so header rows are never modified) and to rely solely onupdateButtons()instead of any one-offdisabledassignments, keeping the logic more maintainable.
Your core add/remove row/column functionality and min/max guards are otherwise solid, and with these adjustments your solution will fully match the intended behavior and be more robust.
✨ 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
| } | ||
| updateButtons(); | ||
| }); | ||
| btnAppendRow.disabled = rowsCount >= maxCount; |
There was a problem hiding this comment.
You only set btnAppendRow.disabled here which leaves the other buttons' initial states undefined. Call updateButtons() once after initialization (instead of this single assignment) to correctly set disabled/enabled states for all four buttons according to current rows/cols, per the requirement to disable buttons at min/max.
| btnRemoveRow.addEventListener('click', (e) => { | ||
| const rows = document.querySelectorAll('tr'); | ||
|
|
||
| if (rows.length > minCount) { |
There was a problem hiding this comment.
This check uses DOM rows.length while the code tracks rowsCount separately. For consistency and to avoid desync between the counter and DOM, use rowsCount in the condition (e.g. if (rowsCount > minCount)) and update the DOM and the counter together.
| const table = document.querySelector('table'); | ||
| let rowsCount = document.querySelectorAll('tr').length; | ||
| const firstRow = document.querySelector('table tr'); | ||
| let colsCount = firstRow ? firstRow.querySelectorAll('td').length : 0; |
There was a problem hiding this comment.
colsCount is computed using firstRow.querySelectorAll('td'). If the first row uses header cells (th) this will return 0 and produce an incorrect initial columns count. Consider using firstRow.querySelectorAll('td, th').length so the initial colsCount reflects header cells as well.
mateacademy-ai-mentor
left a comment
There was a problem hiding this comment.
Review Summary
Your solution is approved because it correctly implements the required growth-table behavior: rows and columns can be added and removed, the 2–10 min/max limits are enforced for both, and the button disabled states are consistently updated on initialization and after each change. The logic in src/scripts/main.js keeps the internal rowsCount/colsCount counters in sync with the DOM, which avoids desynchronization bugs when removing rows or columns. There are no critical issues that would block functionality or violate the task checklist.
As minor improvements, you could refine the column-append handler in src/scripts/main.js so that when it processes the header row (the one containing <th> cells), it appends a <th> instead of a <td> to keep semantic HTML consistent. Similarly, instead of using document.querySelectorAll('tr') in your handlers, prefer table.querySelectorAll('tbody tr') so that body operations don’t accidentally touch header rows and to keep the scope limited to the relevant table. You might also consider extracting a small helper like createCell(isHeader) to centralize cell creation and reduce duplication between row and column operations. Overall, this is a solid, clear implementation that fulfills the functional requirements; the suggestions above are just to improve maintainability and HTML semantics.
✨ Please rate this review in the Platform's notification center1. I will be grateful for your feedback! ✨
https://dianakomar.github.io/js_growth_table_DOM/