Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 41 additions & 1 deletion src/scripts/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Copy link
Copy Markdown

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 final tdCentury is appended to tr.


const tdSex = document.createElement('td');

if (person.sex === 'm') {
tdSex.textContent = 'Male';
} else {
tdSex.textContent = 'Female';
}

tr.append(tdSex);
Copy link
Copy Markdown

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 final tdCentury is appended to tr.


const tdBorn = document.createElement('td');

tdBorn.textContent = person.born;
tr.append(tdBorn);
Copy link
Copy Markdown

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 final tdCentury is appended to tr.

table.append(tr);
Copy link
Copy Markdown

Choose a reason for hiding this comment

The 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);
Copy link
Copy Markdown

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 final tdCentury is appended to tr.


const tdAge = document.createElement('td');

tdAge.textContent = person.died - person.born;
tr.append(tdAge);
Copy link
Copy Markdown

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 final tdCentury is appended to tr.


const tdCentury = document.createElement('td');

tdCentury.textContent = Math.ceil(person.died / 100);
tr.append(tdCentury);
Comment on lines +367 to +398
Copy link
Copy Markdown

Choose a reason for hiding this comment

The 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 table.append(tr) to line 398, after all 6 cells are appended to the row.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Keep only ONE table.append(tr) here at the end of the loop, after tr.append(tdCentury). Delete all the other table.append(tr) calls (lines 367, 378, 384, 390, 396).

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Keep this line, but ensure it's the ONLY table.append(tr) in the loop. After removing line 383, this will be the correct place to append the complete row (with all 6 cells) to the table.

table.append(tr);
});
Loading