I am trying to append an image to appear in the left side div using randomly generated top and left positions, and think that my code is fine, but its not working, can anyone help? When debugging it says
Uncaught SyntaxError: Unexpected identifier.
Uncaught ReferenceError: generateFaces is not defined.
I am confused why the function generateFaces is not defined.
function generateFaces() {
var numberOfFaces = 5;
var theLeftSide = document.getElementById("leftSide");
var this_img = document.createElement("img");
this_img.src = "smile.png";
var random_top = Math.random() * 400;
random_top = Math.floor(random_top);
this_img.style.top = random_top + "px";
var random_left = Math.random() * 400;
random_left = Math.floor(random_left);
this_img.style.left = random_left + "px";
theLeftSide.appendChild(this_img);
}
img {
position: absolute;
}
div {
position: absolute;
}
#leftSide {
width: 500px;
height: 500px;
}
#rightSide {
width: 500px;
height: 500px;
left: 500px;
border-left: 1px solid black;
}
<!DOCTYPE html>
<html>
<head>
<title>Matching Game!</title>
</head>
<body id="theBody" onload="generateFaces()">
<h1>Matching Game</h1>
<p>Click on the extra smiling face on the left.</p>
<div id="leftSide">
</div>
<div id="rightSide">
</div>
</body>
</html>