Let's get started with a JavaScript Prompt Web Page!

  1. Login into your Code.Org account.
  2. Click on your name.
  3. Choose: My Projects
  4. Click on your My First Web Site project.
  5. Click on the Add HTML button.
  6. Right click on: new-4.html
  7. Choose: Rename
  8. Name this file: javascript.html
  9. Delete all the lines in this file.
  10. Copy the JavaScript Prompt Page Template (HTML) code (below).
  11. Paste that code into your form.html file.
  12. Change your page title, your Author name, and your page heading to something appropriate
  13. Click: Refresh and Save

JavaScript Prompt Page Template (HTML)

<!doctype html>
<html>
  <head>
    <title>page title goes here</title>
    <!-- Author: put your name in this comment line -->
    <link href="style.css" rel="stylesheet"/>
    <script>  
      /* put your name in this comment line */
      function promptMe () {
      var person = prompt("Please enter your name", "Bob Dylan");
      if (person != null) {
        document.getElementById("promptDiv").innerHTML =
        "Hello " + person + "! How are you today?";
      }
      if (confirm("OK to continue?")) {
        document.getElementById("confirmDiv").innerHTML =
        "You clicked 'OK'";
      } else {
        document.getElementById("confirmDiv").innerHTML =
        "You clicked '<span style=\"color: red; font-weight: bold;\">Cancel</span>'";
      }
    }
    </script>
  </head>
  <body onload="promptMe();">
      <nav>
      <a href="index.html">Home</a> |
      <a href="table.html">Table</a> |
      <a href="form.html">Form</a> |
      <a href="multimedia.html">Multimedia</a> |
      <a href="javascript.html" class="selected">JavaScript</a> |
      <a href="temperature.html">Temperature</a> |
      <a href="js_styles.html">JS Styles</a>
    </nav>
    <h1>put page heading here</h1>
    <div id="promptDiv">
    </div>
    <div id="confirmDiv">
    </div>
    <p>This page was last modified on: 
     <script>document.write(document.lastModified);</script>.</p>
  </body>
</html>

Example