curriculum/challenges/english/blocks/lab-book-catalog-table/66ec4c8e9878d8441956516f.md
Objective: Fulfill the user stories below and get all the tests to pass to complete the lab.
User Stories:
table element that lists book information.Title, Author, Genre, and Publication Year, in that order.Total Books: N where N should be replaced by the number of books in your table.You should have one table element.
assert.lengthOf(document.querySelectorAll('table'), 1);
You should have one thead element within your table element.
assert.lengthOf(document.querySelectorAll('table thead'), 1);
You should have one tr element within your thead element.
assert.lengthOf(document.querySelectorAll('thead tr'), 1);
You should have four th elements within your thead element's row.
assert.lengthOf(document.querySelectorAll('thead tr th'), 4);
Your four th elements should have the text Title, Author, Genre, and Publication Year, in that order.
const ths = document.querySelectorAll('thead tr th');
assert.equal(ths[0]?.textContent.trim(), 'Title');
assert.equal(ths[1]?.textContent.trim(), 'Author');
assert.equal(ths[2]?.textContent.trim(), 'Genre');
assert.equal(ths[3]?.textContent.trim(), 'Publication Year');
You should have one tbody element within your table element.
assert.lengthOf(document.querySelectorAll('table tbody'), 1);
Your tbody element should have at least five rows.
assert.isAtLeast(document.querySelectorAll('tbody tr').length, 5);
Each row in your tbody element should have exactly four td elements as children.
const rows = document.querySelectorAll('tbody tr');
assert.isAtLeast(rows.length, 1);
rows.forEach(row => {
assert.lengthOf(row.querySelectorAll('td'), 4);
assert.lengthOf(row.children, 4);
});
Each td element in your table body should have text with book information.
const tds = document.querySelectorAll('tbody tr td');
assert.isAtLeast(tds.length, 1);
tds.forEach(td => {
assert.isAtLeast(td.textContent.trim().length, 1);
});
You should have one tfoot element within your table element.
assert.lengthOf(document.querySelectorAll('table tfoot'), 1);
You should have exactly one tr element in your tfoot element.
assert.lengthOf(document.querySelectorAll('tfoot tr'), 1);
The td element in your tfoot element's row should have it's colspan attribute set to 4.
assert.equal(document.querySelector('tfoot tr td')?.colSpan, 4);
The td element in your tfoot element's row should have the text Total Books: N where N is the number of books in your table.
const numberOfBooks = document.querySelectorAll('tbody tr')?.length;
assert.equal(document.querySelector('tfoot tr td').textContent.trim(), `Total Books: ${numberOfBooks}`);
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Book Catalog</title>
</head>
<body>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Book Catalog</title>
</head>
<body>
<h1>Book Catalog</h1>
<table>
<thead>
<tr>
<th>Title</th>
<th>Author</th>
<th>Genre</th>
<th>Publication Year</th>
</tr>
</thead>
<tbody>
<tr>
<td>How to Contribute to Open-Source Projects – A Handbook for Beginners</td>
<td>Hillary Nyakundi</td>
<td>Open Source</td>
<td>2023</td>
</tr>
<tr>
<td>Learn Linux for Beginners: From Basics to Advanced Techniques</td>
<td>Zaira Hira</td>
<td>Linux</td>
<td>2024</td>
</tr>
<tr>
<td>How to Learn to Code and Get a Developer Job</td>
<td>Quincy Larson</td>
<td>Learn To Code</td>
<td>2024</td>
</tr>
<tr>
<td>The Regular Expressions Book – RegEx for JavaScript Developers</td>
<td>Kolade Chris</td>
<td>Regular Expressions</td>
<td>2023</td>
</tr>
<tr>
<td>The Python Code Example Handbook</td>
<td>Farhan Hasin Chowdhury</td>
<td>Python</td>
<td>2023</td>
</tr>
</tbody>
<tfoot>
<tr>
<td colspan="4">Total Books: 5</td>
</tr>
</tfoot>
</table>
</body>
</html>