0

don't worry about what i'm printing to the innerHTML but i was told i could use an variable as an id tag in the "GetElementById" section. I have the tag "1", "2", etc... up to tweleve in my html but i keep getting thrown the error "diceRoller.js:165 Uncaught TypeError: Cannot read property 'innerHTML' of null". am i doing something wrong or will i need to print it all manually?


    for (let i=2, j=0; i<14; i++, j++){

        let id = i;
        if (nTotalRolls>0) {
            document.getElementById(i.toString()).innerHTML += "<td>" + i + "</td>" + "<td>" + naVals[j] + "</td>" + "<td>" + naVals[j] / nTotalRolls * 100 + "</td>";
        }

Another Problem i'm having is with timers

for (let i=0; i<10; i++) {
       
            document.getElementById("image1").src = "images/dice" + int1 + ".png";
            document.getElementById("image2").src = "images/dice" + int2 + ".png";     

    }

I can't for the life of me figure out how to make this loop sleep for 100 milliseconds every time it loops. I'm supposed to use setTimeout but after a couple hours of trying i can't seem to make it work.

Any help will be appreciated thankyou in advance.

Juan184
  • 1
  • 3
  • One question at a time, please. – Barmar Feb 11 '21 at 00:42
  • Use `setInterval()` to run code every 100 milliseconds. – Barmar Feb 11 '21 at 00:43
  • It can't find your ID names. Check if they are IDs not Classes. Using just numbers as ID names is bad practice IMO. Create an array of ID names and iterate through that. COuld be because they are numbers not words – MomasVII Feb 11 '21 at 00:44

0 Answers0