0
\$\begingroup\$

I'm new to game designing and have to create a game for my project but I keep coming across an error to do with:

index.html:93 Uncaught TypeError: Cannot read property 'innerHTML' of undefined

at drawMissiles (index.html:93)

at gameLoop (index.html:140)

Any idea how to fix this problem?

    drawMissiles()
}


function drawMissiles() {
  document.getElementsByTagName('missile')[0].innerHTML   <--- (index.html:93)
    for(var i = 0 ; i < missiles.length ; i++ ) {
        document.getElementById('missile').innerHTML +=
             `<div class='missile1' style='left:${missiles[i].left}px;
              top:${missiles[i].top}px'></div>`;
\$\endgroup\$
1
\$\begingroup\$

You have written

document.getElementsByTagName('missile')[0]

and then later

document.getElementById('missile')

This looks like a typo and you will probably find that document.getElementsByTagName('missile')[0] is equal to null.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .