Q:

How to resolve the below given JS error?

Here is what I am trying to accomplish:
A new variable called theRightSide is created. This points to the right side div e.g.
var theRightSide =
    document.getElementById("rightSide");

After all the images have been created and added to the leftSide div, use cloneNode(true) to copy the leftSide div e.g. leftSideImages = theLeftSide.cloneNode(true);
Then, delete the last child of leftSideImages 
Then, add leftSideImages to the rightSide div
Here 's my code: 
    <html>
    <head>
    <style type="text/css">
        img {
            position:absolute;
        }
        div {
            position:absolute;
            width:500px; 
            height:500px;
        }

        #rightSide { left: 500px; 
            border-left: 1px solid black; 
        }

    </style>

    </head>
    <body onload="generateFaces()">
        <h1>Matching Game</h1>
        <div id="leftSide"></div>
        <div id="rightSide"></div>
        <script>
            var numberOfFaces=5;
            var theLeftSide = document.getElementById("leftSide");
            function generateFaces(){
                for (var i = 0; i < numberOfFaces; i++) 
                {
                    var img = document.createElement("IMG");
                    img.src="smile.png";
                    img.style.top=Math.floor(Math.random()*401);
                    img.style.height=100;
                    img.style.left=Math.floor(Math.random()*401);
                    theLeftSide.appendChild(img);

                };
            }

            leftSideImages = theLeftSide.cloneNode(true);
            var theRightSide = document.getElementById("rightSide");
            leftSideImages.removeChild(leftSideImages.lastChild);
            theRightSide.appendChild(leftSideImages);
        </script>
    </body>
</html>

Error:
    Uncaught TypeError: Failed to execute 'removeChild' on 'Node': parameter 1 is not of type 'Node'.
Please help me resolve this two errors.

A:

It seems to suggest that
var theLeftSide = document.getElementById("leftSide");

is returning null. Are you are that element exists and has that id?
Fiddle: http://jsfiddle.net/yuhc6rdm/

