CS 101 - Intro to Computing, Spring 2008

Lab 7

JavaScript Programming

The hardest part about programming is figuring out how to get the computer to do what you want it to do. Once you determine how you would solve a task, you must then specify statements in the computer's programming language that would do the same thing. The problem here is that you must specify EVERYTHING down to the smallest detail to the computer. Humans are smarter than computers, because we can make and understand assumptions about the smaller details.

IF Statement

The if statement allows other statement(s) to be conditionally executed. This means these others statement(s) may or may not get executed depending on the result of a conditional expression. The form of an if statement is:
if ( cond )
            statement
where: if a keyword of the language
cond the conditional expression which will be evaluated to either true or false
statement the other statement(s) that will get execute if the conditional expression evaluates to true.

Conditional Expressions

The conditional expression will normally make use of the relational and boolean operators.

The relational operators are:

= = equal to
!= not equal to
< less than
< less than or equal to
> greater than
>= greater than or equal to
The boolean operators are:

&& and
|| or
! not

Block of Statements

The other statement(s) must be a single statement or a block of statements. The block of statements is a group or zero or more statements enclosed by the curly brace characters: { and }.

IF - ELSE Statement

There is a variation on the if statement. This is the if-else statement. The if-else statement has two sets of other statement(s). The first set is executed if the conditional expression evaluates to true. The second set is executed if the conditional expression evaluates to false. The first set of other statements is normally called the "if clause" or sometimes the "then clause" of the if statement. The second set of other statements is normally called the "else clause" of the if statement. The form of the if-else statement is:
 
if ( cond )
            statement1
else
            statement2
where: if a keyword of the language
cond the conditional expression which will be evaluated to either true or false
statement1 the other statement(s) that will get execute if the conditional expression evaluates to true, the "if clause"
else a keyword of the language
statement2 the other statement(s) that will get execute if the conditional expression evaluates to false, the "else clause"

Nested IF Statements

Often a program will need to check for a number of conditions. This can be done by using nested if statements, which are nothing more than multiple IF-ELSE statements. The else clauses in a Nested if statement always contain either another IF-ELSE statement. The last IF-ELSE statement is sometimes just an if statement. The form is:
if ( cond1 )

            statement1

else if ( cond2 )

            statement2

else if ( cond3 )

            statement3

...

else if ( condN )

            statementN

else

            statementN+1

Lab Assignment

Due: Tuesday 3/4/2008 by 11:59 pm

For this lab assignment, complete the following:

  1. Create an HTML file that lists:

  2. This web page must be placed in your web space (in your WWW directory) on your CS account.

  3. You are also required to put a link on your CS Home Page to the page you created for this lab.

    Verify that your link and the file are viewable via a web browser from the URL of:

         http://www.cs.uic.edu/~USERID
    
    where USERID is your CS account login name.
    
    You can check this out via the link to your home page on the CS 101 Student List page. Once you are at your home page, follow the link you added to your home page for this lab assignment.

  4. You are also to submit the HTML file electronically by using the UNIX turnin command.

    To use the UNIX turnin command to electronically hand-in your html file using the project name of lab7. To submit the file in <filename> for lab7, the turnin command is entered as:

         turnin -c cs101 -p lab7 <filename>
    
    To verify what you submitted using the turnin command type:
         turnin -c cs101 -p lab7 -v
    

Grading Criteria