From 4cde42506c5c15cf0b6d0e2dcc6ba439fe3d1bbb Mon Sep 17 00:00:00 2001 From: Anna Skobara Date: Tue, 9 Jun 2026 10:55:32 +0300 Subject: [PATCH 1/2] add task solution --- .github/workflows/test.yml-template | 29 +++++++++++++++++++++++++++++ README.md | 6 +++--- src/scripts/main.js | 20 +++++++++++++++++++- 3 files changed, 51 insertions(+), 4 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..1f210dbb9 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ 1. Replace `` with your Github username in the link - - [DEMO LINK](https://.github.io/js_task_generate_table_DOM/) + - [DEMO LINK](https://annaskobara.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; @@ -14,12 +14,12 @@ 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. diff --git a/src/scripts/main.js b/src/scripts/main.js index 7d4a5db04..dcf55c71b 100644 --- a/src/scripts/main.js +++ b/src/scripts/main.js @@ -357,4 +357,22 @@ const people = [ // eslint-disable-next-line no-console console.log(people); // you can remove it -// write your code here +const tableBody = document.querySelector('.dashboard'); + +for (const person of people) { + const age = person.died - person.born; + const century = Math.ceil(person.died / 100); + + const row = document.createElement('tr'); + + row.innerHTML = ` + ${person.name} + ${person.sex} + ${person.born} + ${person.died} + ${age} + ${century} + `; + + tableBody.append(row); +} From ab33177b8eaa0ab82cfbce5e724d3297e56fd4cf Mon Sep 17 00:00:00 2001 From: Anna Skobara Date: Tue, 9 Jun 2026 11:09:35 +0300 Subject: [PATCH 2/2] add task solution --- src/scripts/main.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/scripts/main.js b/src/scripts/main.js index dcf55c71b..77594865f 100644 --- a/src/scripts/main.js +++ b/src/scripts/main.js @@ -363,11 +363,19 @@ for (const person of people) { const age = person.died - person.born; const century = Math.ceil(person.died / 100); + let gender = ''; + + if (person.sex === 'm') { + gender = 'Male'; + } else { + gender = 'Female'; + } + const row = document.createElement('tr'); row.innerHTML = ` ${person.name} - ${person.sex} + ${gender} ${person.born} ${person.died} ${age}