Advertisement
Guest User

Untitled

a guest
Jun 7th, 2016
40
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <!DOCTYPE html>
  2. <html>
  3.  
  4.   <head>
  5.     <style>
  6.     img {
  7.       position: absolute;
  8.     }
  9.     div {
  10.       position: absolute;
  11.       width:500px;
  12.       height:500px
  13.     }
  14.     #rightSide {
  15.       left: 500px;
  16.       border-left: 1px solid black;
  17.     }
  18.     </style>
  19.   </head>
  20.  
  21.   <body>
  22.     <h1>Matching Game</h1>Click on the extra smiling face on the left.
  23.     <div id="leftSide"></div>
  24.     <div id="rightSide"></div>
  25.     <script>
  26.     var numberOfFaces = 5;
  27.     var i;
  28.     var theLeftSide = document.getElementById("leftSide");
  29.     var theRightSide = document.getElementById("rightSide");
  30.     var theBody = document.getElementsByTagName("body")[0];
  31.     var leftSideImages;
  32.     document.body.onload = init;
  33.  
  34.     function generateFaces() {
  35.       for(i = 0; i < numberOfFaces; i++) {
  36.         var image = document.createElement("img");
  37.         image.src = "smile.png";
  38.         image.style.top = Math.floor(Math.random() * 400) + "px";
  39.         image.style.left = Math.floor(Math.random() * 400) + "px";
  40.         theLeftSide.appendChild(image);
  41.       }
  42.       leftSideImages = theLeftSide.cloneNode(true);
  43.       leftSideImages.removeChild(leftSideImages.lastChild);
  44.       theRightSide.appendChild(leftSideImages);
  45.       return 0;
  46.     }
  47.  
  48.     function init() {
  49.       generateFaces();
  50.  
  51.       theLeftSide.lastChild.onclick = function nextLevel(event) {
  52.         event.stopPropagation();
  53.         numberOfFaces += 5;
  54.         while(theLeftSide.firstChild) {
  55.           theLeftSide.removeChild(theLeftSide.firstChild);
  56.         }
  57.         while(theRightSide.firstChild) {
  58.           theRightSide.removeChild(theRightSide.firstChild);
  59.         }
  60.         generateFaces();
  61.       }
  62.  
  63.       theBody.onclick = function gameOver() {
  64.         alert("Game Over!");
  65.         //numberOfFaces = initialNumberOfFaces;
  66.         theBody.onclick = null;
  67.         theLeftSide.lastChild.onclick = null;
  68.       }
  69.  
  70.     }
  71.     </script>
  72.   </body>
  73.  
  74. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement