Skip to content

Commit da10150

Browse files
EmperorAliikmtusher97
authored andcommitted
[EmperorAlii] Modify multiplication table
1 parent 8c5261e commit da10150

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

004-number-table/EmperorAlii/multiplication-table.js

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ function checkValidity(number) {
1313

1414
//clearing the input for any previous values
1515
function clearPreviousInputs() {
16-
tableBody.innerText = '';
16+
tableBody.innerHTML = '';
1717
tableBody.classList.remove('bg-red-400');
1818
tableBody.classList.remove('text-white');
1919
numberTableInput.classList.remove('border-red-400');
@@ -29,11 +29,25 @@ function showError() {
2929

3030
//logic for generating table
3131
function multiplicationLogic(inputNumber) {
32+
// Generating table rows and cells
33+
const tableRow = document.createElement('tr');
34+
const cells = [];
35+
36+
// Adding flex and flex-col classes to table row
37+
tableRow.classList.add('flex');
38+
tableRow.classList.add('flex-col');
39+
40+
// Loop to create number table
3241
for (i = 1; i <= 10; i++) {
33-
tableBody.innerText += `
34-
${inputNumber} X ${i} = ${inputNumber * i}
35-
`;
42+
const cell = document.createElement('td');
43+
cell.classList.add('border');
44+
cell.innerText = `${inputNumber} X ${i} = ${inputNumber * i}`;
45+
cells.push(cell);
3646
}
47+
48+
// Appending cells to the row and row to the table body
49+
tableRow.append(...cells);
50+
tableBody.appendChild(tableRow);
3751
}
3852

3953
// Generate Number Table

0 commit comments

Comments
 (0)