Search code examples
javascripthtmltypeerrorpacman

Uncaught TypeError: document.getElementbyId is not a function Pac-man style game


I'm quite new to Javascript and while developing a small Pac-man style game.
I got stuck with this error, unsure what is wrong. Please let me know!

PICTURE 1 Error seen in console PICTURE 2 Error pic in Source

Code here:

...(CSS CODE)...

<script type="text/javascript">

var world =[
[1,1,1,1,1],
[1,0,2,2,1],
[1,2,1,2,1],
[1,2,2,2,1],
[1,1,1,1,1] 
]

 var worldDict ={
    0:'blank',
    1:'wall',
    2:'sushi'
 }

  function drawWorld(){
   output=" ";

for( var row= 0; row<world.length;row++){
    output+= "<div class = 'row'></div>";
    for ( var x= 0; x<world[row].length;x++){
        console.log("Element: ", worldDict[world[row][x]]);
    }
}
document.getElementbyId('world').innerHTML=output;

Solution

  • I think you should capitalize By in you code. Like this:

    document.getElementById('world').innerHTML = output;
    

    the Java script functions are camel case