I am stuck in an exercise for a MOOC. The instructions are the following: "In this function the faces are created in a loop. The loop executes numberOfFaces times. In each iteration"
Five faces are supposed to show on the left side. However, I'm only getting one.
Below you can find my code. Please tell me what I'm doing wrong/how to fix it.
<html>
<head>
<title>Matching Game</title>
<style>
img {position: absolute}
div {width: 500px; height: 500px; position: absolute}
#rightSide {left: 500px; border-left: 1px solid black}
</style>
</head>
<body id = "theBody" onload = "generateFaces()">
<h1 id = "title">Matching Game</h1>
<p id = "instructions"><b>Intructions:</b><br>
Click on the extra smiling face on the left.
Watch out though! If you click on the wrong place, it will be "Game Over"!</p>
<div id = "leftSide"></div>
<div id = "rightSide"></div>
<script>
var numberOfFaces = 5;
var theLeftSide = document.getElementById("leftSide");
function generateFaces() {
for(i = 0; i < numberOfFaces; i++) {
var smilies = document.createElement("img");
smilies.src = "https://home.cse.ust.hk/~rossiter/mooc/matching_game/smile.png";
var top_position = Math.random() * 400;
top_position = Math.floor(top_position);
var left_position = Math.random() * 400;
left_position = Math.floor(left_position);
theLeftSide.style.top = top_position + "px";
theLeftSide.style.left = left_position + "px";
theLeftSide.appendChild(smilies);
}
}
</script>
</body>
</html>
Cheers, J
