To Lecture Notes

IT 238 -- Mar 2, 2026

jQuery Practice Exercises

Examples for Project 4

  1. MathRiddles1 Example
    Display three math riddles and answers in an HTML page like this.
    <!DOCTYPE html>
    <html lang="en">
        <head>
            <meta charset="utf-8">
            <title>MathRiddles1 Example</title>
        </head>
        <body>
            <ol>
                <li><span id="r1">
                    Why is 6 scared of 7?</span><br>
                    <span id="a1">
                    Because 7 8 9.</span>
                    <button>Show Answer for Riddle 1</li>
    
                <li><span id="r2">
                    How can you tell that the three fractions
                    x/c, y/c, and z/c all live in a foreign country?</span><br>
                    <span id="a2">
                    Because they are all over cs.</span>
                    <button>Show Answer for Riddle 2</li>
    
                <li><span id="r3">
                    What did the repeating decimal number say to pi?</span><br>
                    <span id="a3">
                    Don't be so irrational.</span>
                    <button>Show Answer for Riddle 3</li>
            </ol>
        </body>
    </html>
    
    The each answer is hidden, but can be displayed when the button for its riddle is clicked.
    Web Page    Source Code
  2. MathRiddles2 Example
    Same as the MathRiddles1 Example but without the buttons. Click a riddle to make its answer visible.
    Web Page    Source Code
  3. MathRiddles3 Example
    Same as MathRiddles2, but only use one click event handler. This event handler uses an event object to determine which riddle was clicked and then determines the answer to show from the ids of the riddle and answer.
    Web Page   Source Code
  4. MathRiddles4 Example
    Same as MathRiddles3, but no ids are used, only the classes .r for riddles and .a for answers. Use the document.nextElementSibling property to obtain the object representing the answer for the clicked riddle.
    Web Page    Source Code
  5. ReadFromJSON Example
    Place the JSON file riddles.json on your harddrive.  The script then reads the riddles and answers from this JSON file and dynamically loads them into an ordered list.
    Web Page   Source Code
  6. CrapsGame Example
    Play the the dice game on the Web Page. A win is marked with a green check image; a loss is marked with a red X image. Here are the rules for Craps:
    A player, called the shooter, rolls a pair of dice,
    1. if the sum of the dice is 7 or 11, the player wins,
    2. else if the sum of the dice is 2, 3, or 12, the player loses
    3. otherwise the sum is recorded as the point and the player keeps rolling the dice,
    4. if the player obtains the point again before rolling another 7, the player wins,
    5. otherwise the player loses.
    Try it out with this simulation:
    Web Page   Source Code

Project 4

The Date Class

HTTP