Generate a numbered table from rows, columns, and fill order
A teacher wants a quick way to print numbered grids for classroom games: pick how many rows and columns, pick whether the numbers run across or down, and click a button. Build that tool.
The starter code includes the settings:
const MAX_SIZE = 12;
const DEFAULT_ROWS = 3;
const DEFAULT_COLUMNS = 4;
const FILL_ORDERS = [
{ value: 'row', label: 'Row by row' },
{ value: 'column', label: 'Column by column' },
];
Rows, starting at DEFAULT_ROWS.Columns, starting at DEFAULT_COLUMNS.<select> labelled Fill order with one option per entry of FILL_ORDERS (showing its label), starting at Row by row.Generate button.Use a <label> or aria-label for each control. Number inputs (type="number") or text inputs both work.
Generate.<table> with rows table rows of columns cells (<td>), filled with the numbers 1 to rows × columns:
Row by row: left to right across the first row, then the next row, and so on.Column by column: top to bottom down the first column, then the next column, and so on.The table has no header row and no other cells.
Generate again replaces the table. Editing the form without clicking Generate leaves the current table as it is.1 to MAX_SIZE. When the user clicks Generate with an invalid value, show no table and one message, checking rows first:
Rows must be a whole number from 1 to 12.Columns must be a whole number from 1 to 12.A successful Generate hides the message.
Rows 3, Columns 4, Row by row
1 2 3 4
5 6 7 8
9 10 11 12
Rows 4, Columns 3, Column by column
1 5 9
2 6 10
3 7 11
4 8 12
Rows 0 (or 13, 2.5, empty)
"Rows must be a whole number from 1 to 12." and no table
1 × 5 in column order is still 1 2 3 4 5 across."2.5" and "" are not whole numbers.<form> with min/max on the inputs, add noValidate so the browser’s own validation doesn’t block your message.The tests fill in the controls by their labels, click Generate, and read the screen like a user would. You don’t need test ids or specific class names. They check that:
Rows, Columns and Fill order, and the button by the text Generate.<table> after a valid Generate (none before, none after an invalid one), and the text of its <tr>/<td> cells matches the numbers above.Capitalization and extra spacing don’t matter.
| per number and no header row. Only build the table when Generate is clicked, not while the user types. |