-
Notifications
You must be signed in to change notification settings - Fork 1.7k
add task solution #1797
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 task solution #1797
Changes from 1 commit
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,30 @@ const people = [ | |
| // eslint-disable-next-line no-console | ||
| console.log(people); // you can remove it | ||
|
|
||
| // write your code here | ||
| const table = document.querySelector('table'); | ||
|
|
||
| for (const person of people) { | ||
| const tr = document.createElement('tr'); | ||
| const tdName = document.createElement('td'); | ||
| const tdGender = document.createElement('td'); | ||
| const tdBorn = document.createElement('td'); | ||
| const tdDied = document.createElement('td'); | ||
| const tdAge = document.createElement('td'); | ||
| const tdCentury = document.createElement('td'); | ||
|
|
||
| tdName.textContent = person.name; | ||
|
|
||
| if (person.sex === 'm') { | ||
| tdGender.textContent = 'Male'; | ||
| } else { | ||
| tdGender.textContent = 'Female'; | ||
| } | ||
|
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 logic for displaying the gender is almost there. However, one of the core requirements is to match the final visual output with the reference image. The reference image shows 'm' and 'f' for the gender column, not 'Male' and 'Female'. You can simplify this block by directly assigning |
||
|
|
||
| tdBorn.textContent = person.born; | ||
| tdDied.textContent = person.died; | ||
| tdAge.textContent = person.died - person.born; | ||
| tdCentury.textContent = Math.ceil(person.died / 100); | ||
|
|
||
| tr.append(tdName, tdGender, tdBorn, tdDied, tdAge, tdCentury); | ||
| 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.
According to the task description, you should find the table by its class, which is
dashboard. Whiledocument.querySelector('table')might work in this case, it's not as specific as required. It's good practice to use the most specific selector available, likedocument.querySelector('.dashboard').