Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@
<title>Title</title>
<link
rel="stylesheet"
href="./styles/main.scss"
href="src/styles/main.scss"

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 task guideline expects the main SCSS to be linked in a way Parcel can treat it as the entry (e.g., href="./styles/main.scss" from src/index.html), and the previous review explicitly required ensuring a real src/styles/main.scss file exists. Right now the link uses src/styles/main.scss, and there’s no evidence that this file exists or that the path matches the expected setup. Please confirm the stylesheet file is present under src/styles/ and adjust the href to the correct relative path so Parcel can compile and apply the styles as intended.

/>
</head>
<body>
<div id = 'tree'></div>
<script src="scripts/main.js"></script>
</body>
</html>
19 changes: 18 additions & 1 deletion src/scripts/main.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
'use strict';

//const { createElement } = require("react");

const food = {
Drink: {
Wine: {},
Expand All @@ -21,7 +23,22 @@ const food = {
const tree = document.querySelector('#tree');

function createTree(element, data) {
// WRITE YOUR CODE HERE

if (!data || typeof data !== 'object') 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 guard correctly prevents processing non-object data, but since you immediately check for empty objects on the next line, !data is redundant here. You can simplify to just the typeof data !== 'object' check if you want, although this is not functionally incorrect.

if (!data || !Object.keys(data).length) 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 is the right fix to avoid creating <ul> elements when data has no keys, ensuring leaf nodes like Wine and Banana don’t get empty nested lists and aligning with the Cypress test requirement. No change needed here, just noting this is correctly placed before ul creation.


const ul = document.createElement('ul');
Comment on lines +27 to +30

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

createTree always creates and appends a <ul> even when data is an empty object, so leaf nodes get an empty nested list; add a check for Object.keys(data).length and skip creating/appending the ul (and recursion) when there are no children, as required.


for (const objs in data) {
const newel = document.createElement('li');
newel.textContent = objs;

createTree(newel, data[objs]);
Comment on lines +32 to +36

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 createTree call will create nested <ul> elements even when data[objs] is an empty object, because the recursive call always runs. Tests and the example tree likely expect no child <ul> inside leaf <li> nodes. Consider checking if data[objs] has any keys before calling createTree and appending a nested list.


ul.append(newel);
}

element.append(ul);
}

createTree(tree, food);
Loading