diff --git a/README.md b/README.md index a4241d05f..0f4fc422c 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://azesmmisha.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..f11a6328c 100644 --- a/src/scripts/main.js +++ b/src/scripts/main.js @@ -357,4 +357,19 @@ const people = [ // eslint-disable-next-line no-console console.log(people); // you can remove it -// write your code here +const table = document.querySelector('.dashboard'); + +for (const person of people) { + const row = ` + + ${person.name} + ${person.sex === 'm' ? 'Male' : 'Female'} + ${person.born} + ${person.died} + ${person.died - person.born} + ${Math.ceil(person.died / 100)} + + `; + + table.insertAdjacentHTML('beforeend', row); +} diff --git a/src/styles/main.scss b/src/styles/main.scss index 86e5d60d1..0f246e6b1 100644 --- a/src/styles/main.scss +++ b/src/styles/main.scss @@ -1,14 +1,17 @@ body { - background-image: linear-gradient(45deg, #e25644, #7e7cf9); - background-attachment: fixed; display: flex; - justify-content: center; align-items: center; + justify-content: center; + + box-sizing: border-box; min-height: 100vh; + margin: 0; padding: 100px; + font-family: Roboto, sans-serif; - margin: 0; - box-sizing: border-box; + + background-image: linear-gradient(45deg, #e25644, #7e7cf9); + background-attachment: fixed; } table { @@ -18,8 +21,8 @@ table { } tr { - background: #fff; color: #808080; + background: #fff; } tr:nth-child(2n + 1) { @@ -27,14 +30,14 @@ tr:nth-child(2n + 1) { } table tr:first-child { - background: #e25644; color: #fff; + background: #e25644; } td, th { - text-align: left; padding: 18px; + text-align: left; } table tr:last-child td:first-child { @@ -54,7 +57,7 @@ table tr:first-child th:last-child { } tr:not(:first-child):hover { - background: #f5f5f5; - color: #585858; cursor: pointer; + color: #585858; + background: #f5f5f5; }