To Lecture Notes

IT 238 -- Jun 4, 2025

Review Exercises

  1. Find the mistakes in the PirateMap Exercise, which is Problem 1 of the Takehome Final Exam Practice Problems. The corrected version is shown at the end of that exercise.
  2. Design an HTML form with one field fname. If this field is missing when the form is submitted, post the error message "First name is a required field." under the input element for fname. Then cancel the form submission. Answer:
    <!DOCTYPE html>
    <html lang="en">
        <head>
            <meta charset="UTF-8">
            <title>Exercise 4</title>
            <style>
            #notify { color: red; display: none; }
            </style>
            <script>
            function checkSubmit(e) {
                var fname = document.getElementById("fname").value;
                var notification = document.getElementById("notify");
                if (fname == "") {
                    notification.style.display = "block"
                    e.preventDefault( );
                }
                else {
                    notification.style.display = "none";
                }
            }
    
            function init( ) {
                document.getElementById("form1").addEventListener("submit",
                checkSubmit);
            }
            window.addEventListener("load", init);
            </script>
        </head>
        <body>
            <h1>Exercise 4</h1>
            <form id="form1"
                  action="http://ectweb.cs.depaul.edu/sjost/receipt.php"
                  method="POST">
                <label for="fname">First Name:</label><br>
                <input type="text" id="fname" name="fname"><br>
                <span id="notify">First name is a required field<br>.</span><br>
    
                <input type="submit" value="Submit Form">
            </form>
        </body>
    </html>
    
  3. Look at The Date Class document. Write a page that displays the full date and time every second, by using the Date class.
  4. What is wrong with this form?
    <form action="https:www.server.com/receipt.php" method="get">
        <input type="text" placeholder="Enter your name:"><br>
        <input type="number" placeholder="Enter your age:">
    </form>
    
    Answer: both the name and age fields must have name attributes for these values to be sent to the server.
  5. Write an HTML page that implements a square root calculator. Use an input element with type="number" and step="any". Answer:
    <!DOCTYPE html>
    <html lang="en">
        <head>
            <meta charset="UTF-8">
            <title>Square Root Calculator</title>
            <script>
            window.onload = ( ) => {
                document.querySelector("#btn1").onclick = ( ) => {
                    var x = document.querySelector("#in1").value;
                    var output = document.querySelector("#out1");
                    output.value = Math.sqrt(x);
                };
            };
            </script>
        </head>
        <body>
            <h1>Square Root Calculator</h1>
            <input type="number" step="any" id="in1"><br><br>
            <button id="btn1">Compute Square Root</button>
            <input type="text" id="out1">
        </body>
    </html>
    

Animation

More about Arrays

Two Dimensional Arrays

Slide Down/Up Example

Fade In/Out Example

JavaScript Recommendations and Tips from W3Schools