diff --git a/README.md b/README.md index a4241d05f..b7552eb61 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://PatronXXi.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..dc6482802 100644 --- a/src/scripts/main.js +++ b/src/scripts/main.js @@ -358,3 +358,28 @@ const people = [ console.log(people); // you can remove it // write your code here +const dashboard = document.querySelector('.dashboard'); + +people.forEach((person) => { + const row = document.createElement('tr'); + const nameCell = document.createElement('td'); + const sexCell = document.createElement('td'); + const bornCell = document.createElement('td'); + const diedCell = document.createElement('td'); + const ageCell = document.createElement('td'); + const centuryCell = document.createElement('td'); + + nameCell.textContent = person.name; + sexCell.textContent = person.sex === 'm' ? 'Male' : 'Female'; + bornCell.textContent = person.born; + diedCell.textContent = person.died; + ageCell.textContent = person.died - person.born; + centuryCell.textContent = Math.ceil(person.died / 100); + row.appendChild(nameCell); + row.appendChild(sexCell); + row.appendChild(bornCell); + row.appendChild(diedCell); + row.appendChild(ageCell); + row.appendChild(centuryCell); + dashboard.appendChild(row); +});