Skip to content
Open
Show file tree
Hide file tree
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
29 changes: 29 additions & 0 deletions .github/workflows/test.yml-template
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Test

on:
pull_request:
branches: [ master ]

jobs:
build:

runs-on: ubuntu-latest

strategy:
matrix:
node-version: [20.x]

steps:
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- run: npm install
- run: npm start & sleep 5 && npm test
- name: Upload tests report(cypress mochaawesome merged HTML report)
if: ${{ always() }}
uses: actions/upload-artifact@v2
with:
name: report
path: reports
38 changes: 35 additions & 3 deletions src/scripts/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,39 @@ const people = [
},
];

// eslint-disable-next-line no-console
console.log(people); // you can remove it
const table = document.querySelector('.dashboard');
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Consider guarding the table query before using it to avoid runtime errors when .dashboard is not present. For example: const table = document.querySelector('.dashboard'); if (!table) { /* handle missing element or return */ }

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

You query the table with document.querySelector('.dashboard') but there is no check that table is non-null. If the element isn't present this will throw when you call table.append(row). Consider guarding early, e.g. if (!table) return; before iterating over people.


// write your code here
if (table) {
const tableBody = table.querySelector('tbody') || table;

people.forEach((person) => {
const row = document.createElement('tr');

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

cellName.textContent = person.name;

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

cellGender.textContent = person.sex === 'm' ? 'Male' : 'Female';

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

cellBorn.textContent = person.born;

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

cellDied.textContent = person.died;

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

cellAge.textContent = person.died - person.born;

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

cellCentury.textContent = Math.ceil(person.died / 100);

row.append(cellName, cellGender, cellBorn, cellDied, cellAge, cellCentury);
tableBody.append(row);
});
}
Loading