From d26ae314bcb61d89c795382804a6aea2c06ab8d2 Mon Sep 17 00:00:00 2001 From: Rostyslav Date: Sat, 9 May 2026 01:40:53 +0300 Subject: [PATCH 1/3] Solution --- README.md | 6 +++--- src/scripts/main.js | 18 +++++++++++++++++- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index a4241d05f..0b0690b3e 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://Rostyslav452.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..9f55533ae 100644 --- a/src/scripts/main.js +++ b/src/scripts/main.js @@ -357,4 +357,20 @@ const people = [ // eslint-disable-next-line no-console console.log(people); // you can remove it -// write your code here +const table = document.querySelector('.dashboard'); + +const rowsHtml = people + .map( + (p) => ` + ${p.name} + ${p.sex} + ${p.born} + ${p.died} + ${p.died - p.born} + ${Math.ceil(p.born / 100)} + + `, + ) + .join(''); + +table.insertAdjacentHTML('beforeend', rowsHtml); From 150c933295d0ec2a182ccce1280b93baffe26f4e Mon Sep 17 00:00:00 2001 From: Rostyslav Date: Sat, 9 May 2026 01:57:00 +0300 Subject: [PATCH 2/3] Solution --- 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 9f55533ae..e23773a02 100644 --- a/src/scripts/main.js +++ b/src/scripts/main.js @@ -367,7 +367,7 @@ const rowsHtml = people ${p.born} ${p.died} ${p.died - p.born} - ${Math.ceil(p.born / 100)} + ${Math.ceil(p.died / 100)} `, ) From ae3774766a061df0e33d1933c47848ff5cc4da00 Mon Sep 17 00:00:00 2001 From: Rostyslav Date: Sat, 9 May 2026 02:07:36 +0300 Subject: [PATCH 3/3] Solution --- src/scripts/main.js | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/src/scripts/main.js b/src/scripts/main.js index e23773a02..b5230d374 100644 --- a/src/scripts/main.js +++ b/src/scripts/main.js @@ -360,17 +360,21 @@ console.log(people); // you can remove it const table = document.querySelector('.dashboard'); const rowsHtml = people - .map( - (p) => ` + .map((p) => { + const gender = p.sex === 'f' ? 'Female' : 'Male'; + const century = Math.ceil(p.died / 100); + const age = p.died - p.born; + + return ` ${p.name} - ${p.sex} + ${gender} ${p.born} ${p.died} - ${p.died - p.born} - ${Math.ceil(p.died / 100)} + ${age} + ${century} - `, - ) + `; + }) .join(''); table.insertAdjacentHTML('beforeend', rowsHtml);