Skip to content

add task solution#1719

Open
fedechkova wants to merge 3 commits intomate-academy:masterfrom
fedechkova:develop
Open

add task solution#1719
fedechkova wants to merge 3 commits intomate-academy:masterfrom
fedechkova:develop

Conversation

@fedechkova
Copy link

No description provided.

Copy link

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

Choose a reason for hiding this comment

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

Review Summary

Great job on implementing the recursive logic to traverse the data object! The way you handle nested levels is well done. However, this requires changes because the current implementation produces invalid HTML, which is a core requirement of the task.

Your createTree function in src/scripts/main.js appends <li> elements directly to the <div> container. According to HTML standards, <li> elements must be direct children of a <ul> or <ol> tag. To fix this, you should ensure that the very first set of list items is also wrapped in a <ul> element inside the container.

You're very close to a complete solution! Address this structural issue, and you'll be all set.


✨ 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 on lines +23 to +37
function createTree(element, data) {
// WRITE YOUR CODE HERE
for (const key in data) {
const li = document.createElement('li');

li.textContent = key;
element.appendChild(li);

if (Object.keys(data[key]).length) {
const ul = document.createElement('ul');

li.appendChild(ul);
createTree(ul, data[key]);
}
}
}

Choose a reason for hiding this comment

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

This function's logic incorrectly handles the initial call. It assumes the element it receives is a list element (<ul>) that can have <li> children. However, the initial call passes a <div>. Appending <li> elements directly to a <div> creates an invalid HTML structure. A proper list must be wrapped in a <ul> (or <ol>) element. The function should create a main <ul> element inside the container element.

/>
</head>
<body>
<div id="tree"></div>

Choose a reason for hiding this comment

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

The task is to create a nested ul/li list. When your createTree function runs, it will append <li> elements directly into this <div>. This is not valid HTML, as <li> elements must be direct children of a <ul> or <ol>. To ensure the generated list is semantically correct, this root container should be a <ul>.

Copy link

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

Choose a reason for hiding this comment

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

Review Summary

Thanks for addressing the previous feedback! While the list is now correctly placed inside the container, this submission requires changes because the generated HTML structure is invalid and doesn't meet the core requirements.

The main issue is in your recursive logic. For every key, you are creating a new <ul> and putting the key's text directly inside it. According to HTML rules, a <ul> can only contain <li> elements, and text should be placed within an <li>.

To fix this, please adjust your approach: for each level of the object, you should create a single <ul>. Then, loop through all keys at that level and create a separate <li> for each one. The key's text goes inside the <li>, and if there's a nested object, the new <ul> for the next level should also be appended inside that same <li>.

You're very close! Just focus on getting that <ul>/<li> relationship right.


✨ 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 on lines +24 to +36
for (const key in data) {
const ul = document.createElement('ul');

ul.textContent = key;
element.appendChild(ul);

if (Object.keys(data[key]).length) {
const li = document.createElement('li');

ul.appendChild(li);
createTree(li, data[key]);
}
}

Choose a reason for hiding this comment

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

The logic in this loop creates an incorrect HTML structure for the list. Here's a breakdown:

  1. A <ul> is created for every key: A new list is created for each item (e.g., 'Drink', 'Fruit'). Instead, items at the same level should be <li> elements within a single, shared <ul>.
  2. Text is in the <ul>: The item's text (the key) is being put directly into the <ul> element. Text should be inside an <li> element.
  3. An <li> is created conditionally: An <li> is only created if there's a nested object. An <li> should be created for every key to hold its text.

The correct approach is to create one <ul> per level of nesting, and then loop to create an <li> for each key within that <ul>.

Copy link

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

Choose a reason for hiding this comment

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

Review Summary

Excellent work on this submission! You've done a fantastic job addressing the feedback from the previous review. The recursive logic for building the tree is now implemented perfectly, and the generated HTML structure is valid. Your solution fully meets all the requirements of the task. I am happy to approve this submission. Well done!


✨ Please rate this review in the Platform's notification center1. I will be grateful for your feedback! ✨

Footnotes

  1. Rate AI review example

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