To Lecture Notes

IT 238 -- May 4, 2026

Practice Exercises

  1. What do these four document methods do:
    querySelector  querySelectorAll  createElement  appendChild
    
    querySelector -- Creates a JavaScript object that represents the first element specified by the selector. Selectors can be element selectors (e.g., "input"), id selectors (e.g., "#btn1"), or class selectors (e.g.,"red")
    querySelectorAll -- Creates an array of JavaScript objects that represent all of the elements specified by the selector.

    createElement
    -- Creates a JavaScript object from scratch that represents an HTML element specified by an element selector, e.g.,
    var paraObj = document.createElement("p");
    
    appendChild -- Adds an element to the DOM tree by adding it as the last child of the parent object, e.g.,
    olObj.appendChild(liObj);
    
  2. Modify the exercise from last time (Mar 2), by adding this line at the bottom of the body showing which questions were answered correctly, for example:
    1. Correct 2. Incorrect 3. Correct
    
    Answer: add this empty paragraph to the end of the body:
    <p id="details"></p>
    
    Modify the script.js file to look like this:
    function computeScore( ) {
        const correctAnswers = ["", "b", "c", "a"];
        var numCorrect = 0;
        var details = "";
        for(var i = 1; i <= 3; i++) {
            var isCorrect = false;
            for(var j = 1; j <= 3; j++) {
                var rb = document.getElementById("" + i + j);
                if (rb.checked && rb.value == correctAnswers[i]) {
                    numCorrect++;
                    isCorrect = true;
                }
            }
            var word = isCorrect ? "Correct" : "Incorrect";
            details += `${i}: ${word} `;
        }
        var outputPara = document.getElementById("numcorrect");
        outputPara.innerHTML = "Number correct: " + numCorrect;
        var detailsPara = document.getElementById("details");
        detailsPara.innerHTML = details;
    }
    
    function init( ) {
        var button1 = document.getElementById("btn1");
        button1.addEventListener("click", computeScore);
    }
    
    window.addEventListener("load", init);
    

Project 4

HTTP

Submission Forms

We will discuss this section on Mar 9.

Form Validation -- Part A

We will discuss this section on Mar 9.