JavaScript Programming Basics

PROGRAMMING LAB 2
E
NTRANCE ASSIGNMENT

due at the beginning of Programming Lab 2


Review Of: If Statements


Assignment

Think about each question carefully and then, using information from the textbook, your class notes, and your own intelligence, formulate an answer. Write your answers on a separate sheet of paper or print this assignment and write your answers on the printed copy.

  1. For what possible values of x and y are statements A and B executed in the following two structures?
    1. if ( x == 1 )
          if ( y == 7 )
      	statement A      Done when:
          else
      	statement B      Done when:
      
    2. if ( x == 1 )
      {
          if ( y == 7 )
      	statement A      Done when:
      }
      else
          statement B          Done when:
      
  2. Are either of the structures in Exercise 1 equivalent to the following?
    if ( ( x == 1 )  && ( y == 7 ) )
        statement A
    else
        statement B
        

  3. What is the output of the following code?

    1. Code piece number 1
        j = 1;                              
        if ( j == 1 )                       
        {                                
           document.writeln ("String 1");      
           j++;                                
        }                                 
        if ( j == 2 )                      
        {                                   
           document.writeln ("String 2");      
           j++;                       
        }                              
        if ( j == 3 )                   
        {                                
           document.writeln ("String 3"); 
           j++;                            
        }                                   
        
    2. Code piece number 2
        j = 1;
        if ( j == 1 )
        {
           document.writeln ("String 1");
           j++;
        }
        else if ( j == 2 )
        {
           document.writeln ("String 2");
           j++;
        }
        else if ( j == 3 )
        {
           document.writeln ("String 3");
           j++;
        }
        


Copyright 1999, Alyce Faulstich Brady, Kalamazoo College