-
Notifications
You must be signed in to change notification settings - Fork 1.7k
add solution #1821
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
add solution #1821
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -357,4 +357,44 @@ const people = [ | |
| // eslint-disable-next-line no-console | ||
| console.log(people); // you can remove it | ||
|
|
||
| // write your code here | ||
| const table = document.querySelector('.dashboard'); | ||
|
|
||
| people.forEach((person) => { | ||
| const tr = document.createElement('tr'); | ||
| const tdName = document.createElement('td'); | ||
|
|
||
| tdName.textContent = person.name; | ||
| tr.append(tdName); | ||
|
|
||
| const tdSex = document.createElement('td'); | ||
|
|
||
| if (person.sex === 'm') { | ||
| tdSex.textContent = 'Male'; | ||
| } else { | ||
| tdSex.textContent = 'Female'; | ||
| } | ||
|
|
||
| tr.append(tdSex); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Move this |
||
|
|
||
| const tdBorn = document.createElement('td'); | ||
|
|
||
| tdBorn.textContent = person.born; | ||
| tr.append(tdBorn); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Move this |
||
| table.append(tr); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove this line. The row is being appended prematurely after only 3 cells (name, sex, born). The row should only be appended to the table after ALL 6 cells are added to it. |
||
|
|
||
| const tdDied = document.createElement('td'); | ||
|
|
||
| tdDied.textContent = person.died; | ||
| tr.append(tdDied); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Move this |
||
|
|
||
| const tdAge = document.createElement('td'); | ||
|
|
||
| tdAge.textContent = person.died - person.born; | ||
| tr.append(tdAge); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Move this |
||
|
|
||
| const tdCentury = document.createElement('td'); | ||
|
|
||
| tdCentury.textContent = Math.ceil(person.died / 100); | ||
| tr.append(tdCentury); | ||
|
Comment on lines
+367
to
+398
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The row is being appended to the table after EACH cell (lines 367, 373, 379, 385, 391, 397). This causes the row to move to the table after the first cell, and all subsequent cells are appended directly to the table instead of the row. Move There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Keep only ONE There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Keep this line, but ensure it's the ONLY |
||
| table.append(tr); | ||
| }); | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Move this
table.append(tr)outside the cell-creation loop. It should be deleted here and called only once after the finaltdCenturyis appended totr.