From 7686962c4e54205823a9a8308e01b1bf67c7cc44 Mon Sep 17 00:00:00 2001 From: Saper Date: Sat, 7 Nov 2026 13:44:44 +0100 Subject: [PATCH 1/2] Solution --- .github/workflows/test.yml-template | 29 ++++++++++++++++++++++++++++ README.md | 25 +++++++++++++----------- src/scripts/main.js | 30 ++++++++++++++++++++++++++--- 3 files changed, 70 insertions(+), 14 deletions(-) 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 000000000..44ac4e963 --- /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 diff --git a/README.md b/README.md index a4241d05f..b99995e54 100644 --- a/README.md +++ b/README.md @@ -1,32 +1,35 @@ 1. Replace `` with your Github username in the link - - [DEMO LINK](https://.github.io/js_task_generate_table_DOM/) + - [DEMO LINK](https://.github.io/js_task_generate_table_DOM/) 2. Follow [this instructions](https://mate-academy.github.io/layout_task-guideline/) - - 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. + - 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. ### Task: Generate dashboard from JSON This task requires knowledge of how HTML table works. You can learn it here: - - [MDN HTML table basics](https://developer.mozilla.org/en-US/docs/Learn/HTML/Tables/Basics) + +- [MDN HTML table basics](https://developer.mozilla.org/en-US/docs/Learn/HTML/Tables/Basics) Okay, now we know what is a table, and can do some magic. In `main.js`, you already have imported file `people.json`. Variable `people` contains an array of people, you can check it by using `console.log`. Your task today is to convert this array to table rows. -Your layout for start: +Your layout for start: ![Preview](./src/images/preview.png) From the preview, you can see that table has 6 headers, but our data does not contain age and century. Yes, you need to calculate them by yourself. - + ##### Steps to do this challenge: -1) For each person from `people` array create table row with 6 table cells (name, gender, born, died, age, century) -2) Find a table with class `dashboard` in the document. -3) Append created row to table. -4) Done. + +1. For each person from `people` array create table row with 6 table cells (name, gender, born, died, age, century) +2. Find a table with class `dashboard` in the document. +3. Append created row to table. +4. Done. Hints: + - Age is `person.died - person.born` - Century:divide year of person's death by 100 `Math.ceil(person.died / 100)` diff --git a/src/scripts/main.js b/src/scripts/main.js index 7d4a5db04..4048b6114 100644 --- a/src/scripts/main.js +++ b/src/scripts/main.js @@ -1,5 +1,7 @@ 'use strict'; +// const { createElement } = require('react'); + const people = [ { name: 'Carolus Haverbeke', @@ -354,7 +356,29 @@ const people = [ }, ]; -// eslint-disable-next-line no-console -console.log(people); // you can remove it - // write your code here +const tabela = document.querySelector('table'); + +people.forEach((p) => { + const row = document.createElement('tr'); + const values = [p.name, p.sex === 'm' ? 'Male' : 'Female', p.born, p.died]; + + values.forEach((value) => { + const cell = document.createElement('td'); + + cell.textContent = value; + row.append(cell); + }); + + const ageCell = document.createElement('td'); + + ageCell.textContent = p.died - p.born; + row.append(ageCell); + + const centuryCell = document.createElement('td'); + + centuryCell.textContent = Math.ceil(p.died / 100); + row.append(centuryCell); + + tabela.append(row); +}); From 800b6e432d9d62e748a00b5e0fab9040e08e22f2 Mon Sep 17 00:00:00 2001 From: Saper Date: Sat, 7 Nov 2026 13:48:48 +0100 Subject: [PATCH 2/2] Solution2 --- src/scripts/main.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/scripts/main.js b/src/scripts/main.js index 4048b6114..098f04bc7 100644 --- a/src/scripts/main.js +++ b/src/scripts/main.js @@ -357,7 +357,7 @@ const people = [ ]; // write your code here -const tabela = document.querySelector('table'); +const tabela = document.querySelector('.dashboard'); people.forEach((p) => { const row = document.createElement('tr');