tree form object#1773
Conversation
mateacademy-ai-mentor
left a comment
There was a problem hiding this comment.
Review Summary
I am requesting changes because there is a critical DOM bug that breaks the core functionality and causes the tests to fail. In src/index.html, the container is declared as <div id="#tree">, but in your JS you call document.querySelector('#tree'); the id must be tree (without #) so the selector can find it, otherwise tree is null and createTree(tree, food) throws a TypeError when it tries to append to null [CHECKLIST ITEM #3, #5]. Please change this to:
<div id="tree"></div>and ensure the script still queries with document.querySelector('#tree'). After fixing that, re-run the tests (npm run test and the specified test:only commands) to confirm that the Cypress error is gone and all tests execute. As a minor (non-blocking) improvement, you can also avoid calling createTree for empty child objects to skip unnecessary recursive calls, but this is optional. Your recursive logic itself is solid; once the DOM element mismatch is fixed, your solution should behave as intended.
✨ 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
| /> | ||
| </head> | ||
| <body> | ||
| <div id="#tree"></div> |
There was a problem hiding this comment.
The id value should not contain #. With id="#tree", document.querySelector('#tree') in your JS won’t find this element, so tree will be null and createTree(tree, food) will fail. Change this to id="tree" to match the selector.
| if (Object.keys(data).length === 0) { | ||
| return; |
There was a problem hiding this comment.
This early return prevents any ul from being appended when data has no keys. Depending on the tests, they may expect an empty ul for empty objects; double-check the task/tests and adjust if an empty list should still be rendered.
mateacademy-ai-mentor
left a comment
There was a problem hiding this comment.
Review Summary
I am approving your solution because it now meets all the core functional and technical requirements of the task. Your createTree(element, data) implementation correctly builds a nested ul/li structure from the object’s keys and uses recursion to handle nested objects as required. The DOM wiring is fixed: the container is declared as <div id="tree"></div> in index.html and matches document.querySelector('#tree') in main.js, so the function operates on a valid element. The SCSS/Parcel setup is respected by linking the main SCSS file directly in the HTML, which aligns with the project instructions.
There are no remaining critical blockers: the tree is built correctly, recursion is implemented properly, and there are no obvious runtime errors for the specified inputs. As a minor, optional improvement, you could check Object.keys(data[key]).length before recursing to avoid creating empty nested <ul> elements for empty child objects, but this is not required for correctness. Overall, you’ve addressed the earlier issues well and delivered a clean, working solution.
✨ Please rate this review in the Platform's notification center1. I will be grateful for your feedback! ✨
Footnotes
|
|
||
| function createTree(element, data) { | ||
| // WRITE YOUR CODE HERE | ||
| if (Object.keys(data).length === 0) { |
There was a problem hiding this comment.
This guard correctly avoids creating an extra <ul> when the current data object has no keys, but you still recursively call createTree on child objects even if they are empty. While not required by the task, you could optionally check Object.keys(data[key]).length before recursing to avoid empty nested lists.
<your_account>with your GitHub username in the linknpm run testcommand to test your code;npm run test:only -- -nto run fast test ignoring linter;npm run test:only -- -lto run fast test with additional info in console, ignoring linter.