Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>JS Bin</title>
</head>
<body>
<div id="top">
    <h1>Pie in the Face</h1>
    <p>Guess how many fingers I'm holding up between 0 and 10.<br />
    If you guess correctly, I get a pie in the face.<br />
    If you guess wrong, you get a pie in the face.</p>
    <input id="answer" />
    <button id="myButton">Submit</button>
  </center></div>
  <div id="container">
    <div id="image"></div>
    <div id="manpie"></div> 
    <div id="girlpie"></div>
  </div>
    <script type="text/javascript">
      var x=Math.random();
          x=11*x;
          x=Math.floor(x);    
          var imgArray = new Array();
          imgArray[0] = new Image();
              imgArray[0].src="http://www.chimply.com/coconut/images/856509";
          imgArray[1] = new Image();
              imgArray[1].src="http://www.chimply.com/coconut/images/856508";
      document.getElementById("myButton").onclick=function() {
          if (x==document.getElementById("answer").value) {
          document.getElementById("image").innerHTML='<img src="'+imgArray[0].src+'" />';
          // what I had document.getElementById("image").innerHTML=imgArray[0].src;
         } else {
         document.getElementById("image").innerHTML='<img src="'+imgArray[1].src+'" />';
         }
      }
    </script>
</body>
</html>
Output

You can jump to the latest bin by adding /latest to your URL

Dismiss x
public
Bin info
saidbakrpro
0viewers