From 58d9766b005f42ce576104de2f9fa003de88d323 Mon Sep 17 00:00:00 2001 From: Tymur Date: Tue, 7 Apr 2026 08:56:55 +0300 Subject: [PATCH 1/3] add task solution --- README.md | 6 +++--- src/scripts/main.js | 28 +++++++++++++++++++++++++++- 2 files changed, 30 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index a4241d05f..8bf725445 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://timurradkevic.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..5dbbabfdb 100644 --- a/src/scripts/main.js +++ b/src/scripts/main.js @@ -357,4 +357,30 @@ const people = [ // eslint-disable-next-line no-console console.log(people); // you can remove it -// write your code here +const table = document.querySelector('table'); + +for (const person of people) { + const tr = document.createElement('tr'); + const tdName = document.createElement('td'); + const tdGender = document.createElement('td'); + const tdBorn = document.createElement('td'); + const tdDied = document.createElement('td'); + const tdAge = document.createElement('td'); + const tdCentury = document.createElement('td'); + + tdName.textContent = person.name; + + if (person.sex === 'm') { + tdGender.textContent = 'Male'; + } else { + tdGender.textContent = 'Female'; + } + + tdBorn.textContent = person.born; + tdDied.textContent = person.died; + tdAge.textContent = person.died - person.born; + tdCentury.textContent = Math.ceil(person.died / 100); + + tr.append(tdName, tdGender, tdBorn, tdDied, tdAge, tdCentury); + table.append(tr); +} From 8f83cef7da752a08fbe88f5b7600f457b53d14c8 Mon Sep 17 00:00:00 2001 From: Tymur Date: Tue, 7 Apr 2026 09:37:34 +0300 Subject: [PATCH 2/3] add task solution --- src/scripts/main.js | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/scripts/main.js b/src/scripts/main.js index 5dbbabfdb..c0d788a81 100644 --- a/src/scripts/main.js +++ b/src/scripts/main.js @@ -357,7 +357,7 @@ const people = [ // eslint-disable-next-line no-console console.log(people); // you can remove it -const table = document.querySelector('table'); +const table = document.querySelector('.dashboard'); for (const person of people) { const tr = document.createElement('tr'); @@ -369,12 +369,13 @@ for (const person of people) { const tdCentury = document.createElement('td'); tdName.textContent = person.name; + tdGender.textContent = person.sex; - if (person.sex === 'm') { - tdGender.textContent = 'Male'; - } else { - tdGender.textContent = 'Female'; - } + // if (person.sex === 'm') { + // tdGender.textContent = 'Male'; + // } else { + // tdGender.textContent = 'Female'; + // } tdBorn.textContent = person.born; tdDied.textContent = person.died; From 9b71b2ac8984fd4c95314d3f07743784d06b5ad1 Mon Sep 17 00:00:00 2001 From: Tymur Date: Tue, 7 Apr 2026 09:44:12 +0300 Subject: [PATCH 3/3] add task solution --- src/scripts/main.js | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/scripts/main.js b/src/scripts/main.js index c0d788a81..2646c99f0 100644 --- a/src/scripts/main.js +++ b/src/scripts/main.js @@ -369,13 +369,12 @@ for (const person of people) { const tdCentury = document.createElement('td'); tdName.textContent = person.name; - tdGender.textContent = person.sex; - // if (person.sex === 'm') { - // tdGender.textContent = 'Male'; - // } else { - // tdGender.textContent = 'Female'; - // } + if (person.sex === 'm') { + tdGender.textContent = person.sex.toUpperCase() + 'ale'; + } else { + tdGender.textContent = person.sex.toUpperCase() + 'emale'; + } tdBorn.textContent = person.born; tdDied.textContent = person.died;