To Lecture Notes

IT 238 -- Jan 26, 2026

Review Exercises

  1. Write a for loop that prints the integers 1 to 1,000 on a browser page. Put 20 numbers on each line. Hint: whenever n % 20 == 0 for a number, write "<br>".
    Answer:
    for(var n = 1; n <= 1000; n++) {
        document.writeln(n + " ");
        if (n % 10 == 0) {
            document.writeln("<br>");
        }
    }
    
  2. How many stars are printed?
    for(var i = 1; i <= 100; i++) {
        for(var j = 1; j <= 200; j++) {
            for(var k = 1; k <= 300; k++) {
                document.writeln("*<br>");
            }
        }
    }
    
    Answer: 100 * 200 * 300 = 6,000,000 (6 million).
    Because these are nested loops, you multiply.
  3. How many stars are printed?
    for(var i = 1; i <= 100; i++) {
        document.writeln("*<br>");
    }
    for(var j = 1; j <= 200; j++) {
        document.writeln("*<br>");
    }
    for(var k = 1; k <= 300; k++) {
        document.writeln("*<br>");
    }
    
    Answer: 100 + 200 + 300 = 6,000 (6 thousand).
    Because these loops are sequential, you add.
  4. This problem was given as part of a job interview programming test, according to the Eloquent JavaScript textbook. Write a loop that prints the numbers from 1 to 100. If a number is divisible by 3, print Fizz after it. If the number is divisible by 5, print Buzz after it. If the number is divisible by both 3 and 5, print Fizz Buzz after it. Here is the beginning of the output:
    1
    2
    3 Fizz
    4
    5 Buzz
    6 Fizz
    7
    8
    9 Fizz
    10 Buzz
    11
    12 Fizz
    13
    15 Fizz Buzz
    16
    17
    ...
    
    Answer:
    for(var i = 1; i <= 100; i++) {
        document.write(i);
        if (i % 3 == 0) {
            document.write(" Fizz");
        }
        if (i % 5 == 0) {
            document.write(" Buzz");
        }
        document.writeln("<br>");
    }
    
  5. Create a textfield that has rounded corners. Also, add a placeholder attribute to the textfield.
    Answer:
    Source code:
    <input type="text" value="Larry" placeholder="Enter name:"
           style="border-radius: 15px; width: 150px; height: 20px;">
    

Expression Interpolation

Comparisons for Equality

Functions vs. Methods

Project 2a

Arrays

Properties and Methods