samedi 23 janvier 2016

Put image on div randomly using javascript

I am making matching game that images in left and right are different, and users have to find(I put one more image in left side). My problem is that I cannot call image on where I want. What should I have to fix? Thank you.

<!DOCTYPE html>
<html>
<head>
<style>
 img {
   position:absolute;
   }
 div {
   position: absolute;
   width: 500px;
   height:500px;
   }
 #leftside {
   float: left;
   }
 #rightside {
   float:right;
   left: 500px;
   border-left: 1px solid black
    }
</style>
<script>
 var numberOfFaces(5);
 var theLeftSide =document.getElementById("leftSide");

 function generateFaces(){
var createElement("img");
var position=Math.floor(Math.random()*500);
img.src='http://ift.tt/1GzZEsa';
 img.id='smileImage';
 createElement.setAttribute("height",position);
 createElement.setAttribute("width",position);
 document.getElementById('leftSide').appendChild(img);
  } 

  </script>
  </head>
  <body>
   <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>




Aucun commentaire:

Enregistrer un commentaire