I have this function that generates a table where users can input numbers from 0-9.
function table(){
let strHTML = "";
strHTML = "<table>";
for(let row = 0; row< 9; row++){
strHTML += "<tr>";
for (let col = 0; col < 9; col++){
strHTML += `<td><input id=${row}-${col} type="number" min="0" max="9" /></td>`;
}
strHTML += "</tr>";
}
strHTML += "</table>";
document.getElementById('myTable').innerHTML = strHTML;
};
I have a function that saves the values from the HTML table in a javascript array.
function saveTable(){
for(let col = 0; col < 9; col++){
for(let row = 0; row < 9; row++){
sudokuArr[col][row] = Number(document.getElementById(col+"-"+row).value);
}
}
};
Finally I have this function which adds two numbers and displays it in a different cell. however whenever this function gets called nothing gets outputted. Not sure what I’m doing wrong?
function calculate(){
var x = sudokuArr[0][0];
var y = sudokuArr[0][8];
var k = x + y;
document.getElementById("0-1").innerHTML = k;
};
ids that start with numbers won't be recognized