From ca42dda572a33d8445d12d15dd755a6b94e7a9da Mon Sep 17 00:00:00 2001 From: pavlo Date: Thu, 7 May 2026 12:55:51 +0300 Subject: [PATCH 1/9] start --- .github/workflows/test.yml-template | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 .github/workflows/test.yml-template diff --git a/.github/workflows/test.yml-template b/.github/workflows/test.yml-template new file mode 100644 index 00000000..44ac4e96 --- /dev/null +++ b/.github/workflows/test.yml-template @@ -0,0 +1,29 @@ +name: Test + +on: + pull_request: + branches: [ master ] + +jobs: + build: + + runs-on: ubuntu-latest + + strategy: + matrix: + node-version: [20.x] + + steps: + - uses: actions/checkout@v2 + - name: Use Node.js ${{ matrix.node-version }} + uses: actions/setup-node@v1 + with: + node-version: ${{ matrix.node-version }} + - run: npm install + - run: npm start & sleep 5 && npm test + - name: Upload tests report(cypress mochaawesome merged HTML report) + if: ${{ always() }} + uses: actions/upload-artifact@v2 + with: + name: report + path: reports From 27217a2fccd4b4a3f6f18535d0663aee1c58b75c Mon Sep 17 00:00:00 2001 From: pavlo Date: Thu, 7 May 2026 18:19:32 +0300 Subject: [PATCH 2/9] prepare --- src/scripts/main.js | 70 ++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 69 insertions(+), 1 deletion(-) diff --git a/src/scripts/main.js b/src/scripts/main.js index 2cdcd10c..6d57ad51 100644 --- a/src/scripts/main.js +++ b/src/scripts/main.js @@ -21,7 +21,75 @@ const food = { const tree = document.querySelector('#tree'); function createTree(element, data) { - // WRITE YOUR CODE HERE + const tree = document.createElement('ul'); + + // tree.textContent = 'Hello World!'; + + for (const key in data) { + const firstList = document.createElement('li'); + + firstList.textContent = key; + + tree.append(firstList); + document.body.append(tree); + + const test = Object.keys(data[key]).length; + + let nested = data[key]; + + if (test !== 0) { + const next = createTree(null, data[key]); + firstList.append(next) + } + } + + return tree; } createTree(tree, food); + +// console.log(food); +// console.log(food.Drink); + + + +// ==== + + // function next() { + // // console.log(data[key]); + // for (const el in data[key]) { + // // console.log(el); + + // const secondList = document.createElement('ul'); + // firstList.append(secondList); + + // const valueSeconList = document.createElement('li'); + // secondList.append(valueSeconList); + + // valueSeconList.textContent = el; + // } + + // // firstList.append(secondList); + // // secondList.append(valueSeconList); + // } + + // if (test !== 0) { + // // console.log(data[key]); + // next(nested); + // } + + // ==== + + // Move function declaration to function body root + + // for (const el in data[key]) { + // console.log(el); + + // const secondList = document.createElement('ul'); + // firstList.append(secondList); + + // const valueSeconList = document.createElement('li'); + // secondList.append(valueSeconList); + + // valueSeconList.textContent = el; + // } From f66f63df64fb82998d949e5948ce413cb84c9a3f Mon Sep 17 00:00:00 2001 From: pavlo Date: Thu, 7 May 2026 18:25:00 +0300 Subject: [PATCH 3/9] updated --- src/scripts/main.js | 65 ++++++--------------------------------------- 1 file changed, 8 insertions(+), 57 deletions(-) diff --git a/src/scripts/main.js b/src/scripts/main.js index 6d57ad51..cd693b27 100644 --- a/src/scripts/main.js +++ b/src/scripts/main.js @@ -21,75 +21,26 @@ const food = { const tree = document.querySelector('#tree'); function createTree(element, data) { - const tree = document.createElement('ul'); - - // tree.textContent = 'Hello World!'; + const myTree = document.createElement('ul'); for (const key in data) { const firstList = document.createElement('li'); firstList.textContent = key; - tree.append(firstList); - document.body.append(tree); - - const test = Object.keys(data[key]).length; + myTree.append(firstList); + document.body.append(myTree); - let nested = data[key]; + const testLength = Object.keys(data[key]).length; - if (test !== 0) { + if (testLength !== 0) { const next = createTree(null, data[key]); - firstList.append(next) + + firstList.append(next); } } - return tree; + return myTree; } createTree(tree, food); - -// console.log(food); -// console.log(food.Drink); - - - -// ==== - - // function next() { - // // console.log(data[key]); - // for (const el in data[key]) { - // // console.log(el); - - // const secondList = document.createElement('ul'); - // firstList.append(secondList); - - // const valueSeconList = document.createElement('li'); - // secondList.append(valueSeconList); - - // valueSeconList.textContent = el; - // } - - // // firstList.append(secondList); - // // secondList.append(valueSeconList); - // } - - // if (test !== 0) { - // // console.log(data[key]); - // next(nested); - // } - - // ==== - - // Move function declaration to function body root - - // for (const el in data[key]) { - // console.log(el); - - // const secondList = document.createElement('ul'); - // firstList.append(secondList); - - // const valueSeconList = document.createElement('li'); - // secondList.append(valueSeconList); - - // valueSeconList.textContent = el; - // } From a198be16bd93fa461600559a914d0e8863fb3f55 Mon Sep 17 00:00:00 2001 From: pavlo Date: Thu, 7 May 2026 18:27:29 +0300 Subject: [PATCH 4/9] updated link --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 0adab1fe..2b00cc56 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Tree from object -Write a function `createTree(element, data)` that creates a nested list of `ul/li` from an object. -Use keys as list items. +Write a function `createTree(element, data)` that creates a nested list of `ul/li` from an object. +Use keys as list items. `element` - is a DOM element @@ -11,7 +11,7 @@ Use keys as list items. ![screenshot of the tree](example/object-tree.png) 1. Replace `` with your GitHub username in the link - - [DEMO LINK](https://.github.io/js_tree-from-object-DOM/) + - [DEMO LINK](https://PAVLO111.github.io/js_tree-from-object-DOM/) 2. Follow [this instructions](https://github.com/mate-academy/js_task-DOM-guideline) - Run `npm run test` command to test your code; - Run `npm run test:only -- -n` to run fast test ignoring linter; From 91041073f6ceb2758345771a1cc911943077349b Mon Sep 17 00:00:00 2001 From: pavlo Date: Thu, 7 May 2026 18:56:28 +0300 Subject: [PATCH 5/9] fixed function --- src/scripts/main.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/scripts/main.js b/src/scripts/main.js index cd693b27..b60bc777 100644 --- a/src/scripts/main.js +++ b/src/scripts/main.js @@ -21,26 +21,26 @@ const food = { const tree = document.querySelector('#tree'); function createTree(element, data) { - const myTree = document.createElement('ul'); + element = document.createElement('ul'); for (const key in data) { const firstList = document.createElement('li'); firstList.textContent = key; - myTree.append(firstList); - document.body.append(myTree); + element.append(firstList); + document.body.append(element); const testLength = Object.keys(data[key]).length; if (testLength !== 0) { - const next = createTree(null, data[key]); + const next = createTree(firstList, data[key]); firstList.append(next); } } - return myTree; + return element; } createTree(tree, food); From 1304797211aa53191fa0511968eee61a7554d01c Mon Sep 17 00:00:00 2001 From: pavlo Date: Fri, 8 May 2026 09:31:16 +0300 Subject: [PATCH 6/9] test --- src/index.html | 1 + src/scripts/main.js | 14 +++++++------- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/index.html b/src/index.html index 3496ee13..506029a4 100644 --- a/src/index.html +++ b/src/index.html @@ -9,6 +9,7 @@ /> +

Hi

diff --git a/src/scripts/main.js b/src/scripts/main.js index b60bc777..db2e8635 100644 --- a/src/scripts/main.js +++ b/src/scripts/main.js @@ -21,26 +21,26 @@ const food = { const tree = document.querySelector('#tree'); function createTree(element, data) { - element = document.createElement('ul'); - for (const key in data) { const firstList = document.createElement('li'); firstList.textContent = key; element.append(firstList); - document.body.append(element); + // document.body.append(firstList); const testLength = Object.keys(data[key]).length; + console.log(testLength) + + if (testLength > 0) { + const ul = document.createElement('ul'); - if (testLength !== 0) { - const next = createTree(firstList, data[key]); + firstList.append(ul); - firstList.append(next); + createTree(null, data[key]); } } return element; } -createTree(tree, food); From 99329da174f8c6669ab04a6452200ee536617e0e Mon Sep 17 00:00:00 2001 From: pavlo Date: Fri, 8 May 2026 09:40:06 +0300 Subject: [PATCH 7/9] test_1.0 --- src/scripts/main.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/scripts/main.js b/src/scripts/main.js index db2e8635..01ab8b08 100644 --- a/src/scripts/main.js +++ b/src/scripts/main.js @@ -30,7 +30,8 @@ function createTree(element, data) { // document.body.append(firstList); const testLength = Object.keys(data[key]).length; - console.log(testLength) + + console.log(testLength); if (testLength > 0) { const ul = document.createElement('ul'); @@ -43,4 +44,3 @@ function createTree(element, data) { return element; } - From 3549b95cd5d51e6141206f9ae78c86bd79c78a39 Mon Sep 17 00:00:00 2001 From: pavlo Date: Fri, 8 May 2026 14:34:33 +0300 Subject: [PATCH 8/9] restart --- src/index.html | 1 - src/scripts/main.js | 69 +++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 66 insertions(+), 4 deletions(-) diff --git a/src/index.html b/src/index.html index 506029a4..3496ee13 100644 --- a/src/index.html +++ b/src/index.html @@ -9,7 +9,6 @@ /> -

Hi

diff --git a/src/scripts/main.js b/src/scripts/main.js index 01ab8b08..b27923fa 100644 --- a/src/scripts/main.js +++ b/src/scripts/main.js @@ -26,12 +26,12 @@ function createTree(element, data) { firstList.textContent = key; - element.append(firstList); - // document.body.append(firstList); + // element.append(firstList); + document.body.append(firstList); const testLength = Object.keys(data[key]).length; - console.log(testLength); + // console.log(testLength); if (testLength > 0) { const ul = document.createElement('ul'); @@ -44,3 +44,66 @@ function createTree(element, data) { return element; } + +// if (tree) { +// createTree(tree, food); +// } + +createTree(tree, food); + +// ==== + +// 'use strict'; + +// const food = { +// Drink: { +// Wine: {}, +// Schnaps: {}, +// }, +// Fruit: { +// Red: { +// Cherry: {}, +// Strawberry: {}, +// }, +// Yellow: { +// Banana: {}, +// Pineapple: {}, +// }, +// }, +// }; + +// const tree = document.querySelector('#tree'); + +// function createTree(element, data) { +// // Твій основний цикл, який ти писав спочатку +// for (const key in data) { +// const firstList = document.createElement('li'); + +// firstList.textContent = key; + +// // Додаємо пункт у поточний список (element) +// element.append(firstList); + +// // Перевіряємо, чи є вкладені елементи +// const test = Object.keys(data[key]).length; + +// if (test > 0) { +// // Якщо є вкладеність, створюємо НОВИЙ список для цього рівня +// const nestedUl = document.createElement('ul'); + +// // Додаємо цей список всередину нашого li +// firstList.append(nestedUl); + +// // Викликаємо функцію знову для вкладеного списку +// // Це і є та сама рекурсія, яка замінює твій цикл "next" +// createTree(nestedUl, data[key]); +// } +// } +// } + +// // Запускаємо один раз для головного контейнера +// // if (tree) { +// // createTree(tree, food); +// // } + +// createTree(tree, food); From eb8eae54d88eca1d5ae3dd99d3397e67c61b1147 Mon Sep 17 00:00:00 2001 From: pavlo Date: Fri, 8 May 2026 15:45:42 +0300 Subject: [PATCH 9/9] fixed problems from menthor --- src/index.html | 3 ++- src/scripts/main.js | 14 ++++++++------ 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/src/index.html b/src/index.html index 506029a4..e5968ddf 100644 --- a/src/index.html +++ b/src/index.html @@ -9,7 +9,8 @@ /> -

Hi

+ + diff --git a/src/scripts/main.js b/src/scripts/main.js index 01ab8b08..3894e1cd 100644 --- a/src/scripts/main.js +++ b/src/scripts/main.js @@ -18,6 +18,11 @@ const food = { }, }; +const rootTree = document.createElement('ul'); + +rootTree.id = 'tree'; +document.body.append(rootTree); + const tree = document.querySelector('#tree'); function createTree(element, data) { @@ -27,20 +32,17 @@ function createTree(element, data) { firstList.textContent = key; element.append(firstList); - // document.body.append(firstList); const testLength = Object.keys(data[key]).length; - console.log(testLength); - if (testLength > 0) { const ul = document.createElement('ul'); firstList.append(ul); - createTree(null, data[key]); + createTree(ul, data[key]); } } - - return element; } + +createTree(tree, food);