iRock

HTML and JavaScript code for this page

  <head>
    <title>iRock - The Virtual Pet Rock</title>

    <script type="text/javascript">
      function touchRock() {
        var userName = prompt("What is your name?", "Enter your name here.");
        if (userName) {
          alert("It is good to meet you, " + userName + ".");
          document.getElementById("rockImg").src = "rock_happy.png";
        } // end if there is a user name
      } // end touchRock()
    </script>
  </head>

  <body onload="alert('Hello, I am your pet rock.');">
    <div style="margin-top:100px; text-align:center">
      <img id="rockImg" src="rock.png" alt="iRock" style="cursor:pointer" onclick="touchRock();" />
    </div>
  </body>