From db7d74e19fcf30e94246e1e8dfc05e12dffc47b5 Mon Sep 17 00:00:00 2001 From: w11ue Date: Wed, 24 Jun 2026 22:51:35 +0200 Subject: [PATCH 1/4] add task solution --- src/scripts/main.js | 57 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) diff --git a/src/scripts/main.js b/src/scripts/main.js index 7d4a5db04..97bd9dd2c 100644 --- a/src/scripts/main.js +++ b/src/scripts/main.js @@ -358,3 +358,60 @@ const people = [ console.log(people); // you can remove it // write your code here +// import people from './people.json'; + +// Функція для обчислення століття +function getCentury(year) { + return Math.ceil(year / 100); +} + +// Отримуємо таблицю з класом dashboard +const table = document.querySelector('.dashboard'); + +// Проходимо по кожній людині з масиву people +people.forEach((person) => { + // Обчислюємо вік + const age = person.died - person.born; + + // Обчислюємо століття (на основі року смерті) + const century = getCentury(person.died); + + // Створюємо новий рядок таблиці + const row = document.createElement('tr'); + + // Створюємо комірки для кожного поля + const nameCell = document.createElement('td'); + + nameCell.textContent = person.name; + + const genderCell = document.createElement('td'); + + genderCell.textContent = person.gender; + + const bornCell = document.createElement('td'); + + bornCell.textContent = person.born; + + const diedCell = document.createElement('td'); + + diedCell.textContent = person.died; + + const ageCell = document.createElement('td'); + + ageCell.textContent = age; + + const centuryCell = document.createElement('td'); + + centuryCell.textContent = century; + + // Додаємо всі комірки до рядка + row.appendChild(nameCell); + row.appendChild(genderCell); + row.appendChild(bornCell); + row.appendChild(diedCell); + row.appendChild(ageCell); + row.appendChild(centuryCell); + + // Додаємо рядок до таблиці + table.appendChild(row); +}); From 4d5f1540041de90547565ee503185e6f71884dc4 Mon Sep 17 00:00:00 2001 From: w11ue Date: Thu, 25 Jun 2026 22:42:05 +0200 Subject: [PATCH 2/4] add task solution --- src/scripts/main.js | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/src/scripts/main.js b/src/scripts/main.js index 97bd9dd2c..02ee9a23d 100644 --- a/src/scripts/main.js +++ b/src/scripts/main.js @@ -358,28 +358,25 @@ const people = [ console.log(people); // you can remove it // write your code here -// import people from './people.json'; -// Функція для обчислення століття function getCentury(year) { return Math.ceil(year / 100); } -// Отримуємо таблицю з класом dashboard const table = document.querySelector('.dashboard'); -// Проходимо по кожній людині з масиву people + people.forEach((person) => { - // Обчислюємо вік + const age = person.died - person.born; - // Обчислюємо століття (на основі року смерті) + const century = getCentury(person.died); - // Створюємо новий рядок таблиці + const row = document.createElement('tr'); - // Створюємо комірки для кожного поля + const nameCell = document.createElement('td'); nameCell.textContent = person.name; @@ -404,7 +401,7 @@ people.forEach((person) => { centuryCell.textContent = century; - // Додаємо всі комірки до рядка + row.appendChild(nameCell); row.appendChild(genderCell); row.appendChild(bornCell); @@ -412,6 +409,5 @@ people.forEach((person) => { row.appendChild(ageCell); row.appendChild(centuryCell); - // Додаємо рядок до таблиці table.appendChild(row); }); From fa4ad7331efb691afd2dd6ae1a70992b0db289b7 Mon Sep 17 00:00:00 2001 From: w11ue Date: Fri, 26 Jun 2026 22:28:31 +0200 Subject: [PATCH 3/4] add task solution --- src/scripts/main.js | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/src/scripts/main.js b/src/scripts/main.js index 02ee9a23d..25db44798 100644 --- a/src/scripts/main.js +++ b/src/scripts/main.js @@ -365,25 +365,20 @@ function getCentury(year) { const table = document.querySelector('.dashboard'); - people.forEach((person) => { - const age = person.died - person.born; - const century = getCentury(person.died); - const row = document.createElement('tr'); - const nameCell = document.createElement('td'); nameCell.textContent = person.name; const genderCell = document.createElement('td'); - genderCell.textContent = person.gender; + genderCell.textContent = person.sex; const bornCell = document.createElement('td'); @@ -401,7 +396,6 @@ people.forEach((person) => { centuryCell.textContent = century; - row.appendChild(nameCell); row.appendChild(genderCell); row.appendChild(bornCell); From ad7ded3b31423100f7167ce43e4c57ab6f203b95 Mon Sep 17 00:00:00 2001 From: w11ue Date: Sat, 27 Jun 2026 23:45:52 +0200 Subject: [PATCH 4/4] add task solution --- src/scripts/main.js | 50 +++++++++++++++++++++++---------------------- 1 file changed, 26 insertions(+), 24 deletions(-) diff --git a/src/scripts/main.js b/src/scripts/main.js index 25db44798..f87843c9d 100644 --- a/src/scripts/main.js +++ b/src/scripts/main.js @@ -365,43 +365,45 @@ function getCentury(year) { const table = document.querySelector('.dashboard'); -people.forEach((person) => { - const age = person.died - person.born; +if (table) { + people.forEach((person) => { + const age = person.died - person.born; - const century = getCentury(person.died); + const century = getCentury(person.died); - const row = document.createElement('tr'); + const row = document.createElement('tr'); - const nameCell = document.createElement('td'); + const nameCell = document.createElement('td'); - nameCell.textContent = person.name; + nameCell.textContent = person.name; - const genderCell = document.createElement('td'); + const genderCell = document.createElement('td'); - genderCell.textContent = person.sex; + genderCell.textContent = person.sex; - const bornCell = document.createElement('td'); + const bornCell = document.createElement('td'); - bornCell.textContent = person.born; + bornCell.textContent = person.born; - const diedCell = document.createElement('td'); + const diedCell = document.createElement('td'); - diedCell.textContent = person.died; + diedCell.textContent = person.died; - const ageCell = document.createElement('td'); + const ageCell = document.createElement('td'); - ageCell.textContent = age; + ageCell.textContent = age; - const centuryCell = document.createElement('td'); + const centuryCell = document.createElement('td'); - centuryCell.textContent = century; + centuryCell.textContent = century; - row.appendChild(nameCell); - row.appendChild(genderCell); - row.appendChild(bornCell); - row.appendChild(diedCell); - row.appendChild(ageCell); - row.appendChild(centuryCell); + row.appendChild(nameCell); + row.appendChild(genderCell); + row.appendChild(bornCell); + row.appendChild(diedCell); + row.appendChild(ageCell); + row.appendChild(centuryCell); - table.appendChild(row); -}); + table.appendChild(row); + }); +}