Skip to content

tree form object#1773

Open
Tendeeer wants to merge 2 commits into
mate-academy:masterfrom
Tendeeer:develop
Open

tree form object#1773
Tendeeer wants to merge 2 commits into
mate-academy:masterfrom
Tendeeer:develop

Conversation

@Tendeeer

Copy link
Copy Markdown
  1. Replace <your_account> with your GitHub username in the link
  2. Follow this instructions
    • Run npm run test command to test your code;
    • Run npm run test:only -- -n to run fast test ignoring linter;
    • Run npm run test:only -- -l to run fast test with additional info in console, ignoring linter.

@mateacademy-ai-mentor mateacademy-ai-mentor left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

  1. Rate AI review example

  2. Re-request AI review example

  3. Add AI review comments example

Comment thread src/index.html Outdated
/>
</head>
<body>
<div id="#tree"></div>

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread src/scripts/main.js
Comment on lines +24 to +25
if (Object.keys(data).length === 0) {
return;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 mateacademy-ai-mentor left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

  1. Rate AI review example

Comment thread src/scripts/main.js

function createTree(element, data) {
// WRITE YOUR CODE HERE
if (Object.keys(data).length === 0) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants