diff options
feat(teaching/upp-2025/w02): Add a button for increasing the available rows in the table
1 files changed, 27 insertions, 3 deletions
| -rw-r--r-- | src/teaching/upp-2025/week02/machine_table.js | 30 |
diff --git a/src/teaching/upp-2025/week02/machine_table.js b/src/teaching/upp-2025/week02/machine_table.js index 99a0255..9aba500 100644 --- a/src/teaching/upp-2025/week02/machine_table.js +++ b/src/teaching/upp-2025/week02/machine_table.js @@ -3,6 +3,21 @@ const machineStyles = document.getElementById("upp2025_w02"); machineStyles.disabled = false; +// Extra rows // + +const rows = document.getElementById("worksheet").children[0]; +const addrowsBtn = document.getElementById("addrows"); + +addrowsBtn.addEventListener('click', function() { + let last = rows.children[rows.children.length - 2]; + for (let i = 1; i <= 10; ++i) { + let row = last.cloneNode(true); + row.children[0].innerText = Number(row.children[0].innerText) + i + rows.insertBefore(row, rows.children[rows.children.length - 1]); + } + memoryRefresh(); +}); + // Execution // const INPUT1 = document.getElementById("input1"); @@ -16,10 +31,16 @@ var speed = 1000; var running = false; var stop = false; -const memory = document.querySelectorAll("#worksheet tr:not(:first-of-type) > td:first-of-type"); -var memoryLocation = memory.length; +var memory = null; +var memoryLocation = -1; var parametrisedCommand = null; +function memoryRefresh() { + memory = document.querySelectorAll("#worksheet tr:not(:first-of-type) > td:first-of-type:not(:last-of-type)"); + memoryLocation = memory.length; +} +memoryRefresh(); + function executeInit() { running = true; A.innerText = 0; @@ -233,7 +254,10 @@ saveBtn.addEventListener('click', function() { function loadMemory(text) { let rows = text.split("\n"); - for (let i = 0; i < memory.length; ++i) { + while (memory.length < rows.length) + addrowsBtn.click(); + + for (let i = 0; i < rows.length; ++i) { memory[i].innerText = rows[i].split(',')[0]; } } |