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
21 changes: 21 additions & 0 deletions projects/chilli-projects/table-maker.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Generate Table</title>
</head>
<body>
<h1>Table Generator</h1>
<h3 for="rows">Number of Rows:</h3>
<input type="number" id="rows" >
<br>
<h3 for="cols">Number of Columns:</h3>
<input type="number" id="cols" >
<br><br>
<button onclick="generateTable()">Generate Table</button>
<div id="tableContainer" style="margin-top: 20px;"></div>

<script src="../chilli-projects/table.js"></script>
</body>
</html>
26 changes: 26 additions & 0 deletions projects/chilli-projects/table.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// generates a table based on user input for rows and columns.

function generateTable() {
let rows = Number(document.getElementById('rows').value);
let cols = Number(document.getElementById('cols').value);
let tableContainer = document.getElementById('tableContainer');
tableContainer.innerHTML = '';

const table = document.createElement('table');
table.style.borderCollapse = 'collapse';
table.style.width = '100%';

for (let i = 0; i < rows; i++) {
const tr = document.createElement('tr');
for (let j = 0; j < cols; j++) {
const td = document.createElement('td');
td.style.border = '1px solid black';
td.style.padding = '8px';
td.textContent = `Row ${i + 1}, Col ${j + 1}`;
tr.appendChild(td);
}
table.appendChild(tr);
}

tableContainer.appendChild(table);
}
1 change: 1 addition & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ This is the main repository for all of the projects in the course.
| 18 | [New Year Countdown](https://github.com/bradtraversy/vanillawebprojects/tree/master/new-year-countdown) | [Live Demo](https://vanillawebprojects.com/projects/new-year-countdown/) |
| 19 | [Speak Number Guessing Game](https://github.com/bradtraversy/vanillawebprojects/tree/master/speak-number-guess) | [Live Demo](https://vanillawebprojects.com/projects/speak-number-guess/) |
| 20 | [Product Filtering UI](https://github.com/bradtraversy/vanillawebprojects/tree/master/product-filtering) | [Live Demo](https://vanillawebprojects.com/projects/product-filtering/) |
| 21 | [Table Generator](projects/chilli-projects/table-maker.html)


NOTE ON PULL REQUESTS: All of these projects are part of the course. While I do appreciate people trying to make some things prettier or adding new features, we are only accepting pull requests and looking at issues for bug fixes so that the code stays inline with the course