COMP 110

First Midtem Exam

This exam is closed book, closed notes, closed computer, closed classmates.

Please put all answers on the test sheets. Make sure your answer is clearly marked and easily distinguished from work you do to get to the solution. You should show your work for partial credit.

When done, please staple together your exams sheets and any paper you use for work and place it face down on the lecture table. Please please print your name clearly below, and sign when you hand in the exam, signifying your adherence to the honor code and attesting to the work being yours alone.



Name (print) ----------------------------------------------------------------


Signed  ---------------------------------------------------------------------

  1. (5%) For this question, you will select from this list of HTML tags:
    (A) < script >   (H) < center >
    (B) < ol >       (I) < hr >
    (C) < body >     (J) < font >
    (D) < title >    (K) < h1 >
    (E) < head >     (L) < br >
    (F) < tr >       (M) < input >
    (G) < ul >       (N) < table >
    (O) < p >        (P) < hr >
    
    In an HTML document, which tag would be used to do each of the following (put the corresponding letter in the blank):
    
       i) __G_____ create an unnumbered list of items
    
      ii) __E_____ create a top level header for the page
    
     iii) __J_____ change the text style to Arial and the color to red
    
      iv) __M_____ create a button to click to run a JavaScript program
    
       v) __L_____ cause a line break      
    
      vi) __F_____ add a new row to a table 
    
     vii) __P_____ create a line horizontally across the page
    
    viii) __A_____ insert a block of JavaScript code
    
      ix) __O_____ skip a line and indent for a new paragraph
    
       x) __D_____ put the phrase "Mortgage Calculator" in the top bar of the browser
    
    
    
    
    
    

  2. (6%) For this question, you will select from this list of items:
    (A) input     (H) integer
    (B) internet  (I) byte
    (C) array     (J) bit
    (D) output    (K) world wide web
    (E) disk      (L) CPU (or ALU)
    (F) function  (M) expression
    (G) string    (N) RAM memory
    
    For each of the following definitions, select the item above that best matches (put the corresponding letter in the blank):
       i) __J_____ single datum of binary information: 0 or 1
    
      ii) __E_____ slow non-volatile storage
    
     iii) __I_____ basic collection of 8 binary data values
    
      iv) __C_____ grouping of variable locations in a program that can be systematically 
                   used by subscript
    
       v) __L_____ place where all arithmetic operations are performed in the computer
    
      vi) __N_____ fast volatile storage
    
    

  3. (4%) Which of the following are not in the group of 6 fundamental concepts of programming that we have studied (write the letters for your choices in the blank)?
    (A) data structure     (F) functions
    (B) HTML               (G) AFS and FTP
    (C) loops              (H) variables and assignment
    (D) conditionals       (I) Javascript
    (E) alert box          (J) expressions and value retrieval 
    
    
    answers: __B,E,G,I_______
    
    

  4. (6%) Consider the number 138 in decimal (base 10). Write the binary (base 2) representation of it. Show your work or explain your reasoning for partial credit.
    
    
    
    
    
    
    
    answer: ___ 10001010 ____
    
    

  5. (6%) Consider the number 10010110 in bianry (base 2). Write the decimal (base 10) representation of this number. Show your work or explain your reasoning for partial credit.
    
    
    
    
    
    
    answer: ____ 150 _______
    
    
    
    

  6. (12%) What is printed in the "alert" box at the end of running this JavaScript code fragment?
       var max = 10;
       var num = 3;
       var k = 5;   // loop index
       while (k < max) {
          num = num + k;
          k = k + 2;
       }
       alert(num);
    
    
    
    
    answer: __ 24 _________ 
    
    
    
    
    
    

  7. (11%) What is printed in the "alert" box at the end of running this JavaScript code fragment?
       var max = 4;
       var num = 2;
       var k ;   // loop index
       for (k = 2; k <= max; k++) {
          num = num * k;
       }
       alert(num);
    
    
    
    
    answer: ___ 48 ________ 
    
    
    
    
    
    

  8. (10%) What is printed in the "alert" box at the end of running this JavaScript code fragment?
       
       var x = 3;
       var f = 12;
    
    
       if (f > 10 ) { f = f * 2 ; }
    
       if (f < 20) { f = f - 2; }
       else { f = 33 - x ; }
    
       if (x < 4 ) { x = x + 2; }
       else if (x > 0) { x = x * 3; }
       else if (x == 5) { x = x - 2 ; }
       else { x = -9 ; }
    
       alert("x: " + x + ", f: " + f);
    
    
    
    
    
    answer: __ x: 5, f: 30 _______ 
    
    
    

  9. (10%) What is printed in the "alert" box at the end of running function "main()" ?
       function main() {
          var some = 5;
          var thing = 10;
          thing = stomp(some);
          alert("some: " + some + ", thing: " + thing);
       }
    
       function stomp (arg) {
          var loc = 3 ;
          var num = -5 ;
          num = arg * loc ;
          return num;
       }
    
    
    
    
    answer: __ some: 5, thing: 15 ______ 
    
    
    
  10. (10%) What is printed in the "alert" box at the end of running this JavaScript code fragment?
       
      var max = 4;
      var arr = new Array(max);
      var k;
      
      for (k=0; k < max; k++) {
         arr[k] = k * 5 ;
      }
    
      alert( arr[2] );
    
    
    
    answer: __ 10 __________ 
    
    
    
    
    
    
  11. (10%) What is printed in the "alert" box at the end of running this JavaScript code fragment?
       
      var k = 2;
      var num = 6;
      
      switch (k) {
        case 0: num = 3; break;
        case 1: num = num + 3; break;
        case 2: num = num * 3; break;
        case 3: num = num - 3; break;
        case 4: num = num / 2; break;
      }
    
      alert( num );
    
    
    
    answer: __ 18 _________ 
    
    
    
    
    

  12. (10%) For part of this question, put in the space given the result produced by each function or expression:
       i) _true___ true || false
    
      ii) _true___ isNaN("midterm");
    
     iii) _false__ isNaN(25);
    
      vi) _12_____ Math.floor(12.98765);
    
       v) _13_____ Math.round(12.98765);
    
      vi) _3______ Math.sqrt(9);
    
     vii) _false__ !true
    
    viii) _false__ true && false
    
      ix) _-225___ Number("-225");
     
       x) _2______ 10 % 4
    
    
    Note: what we are asking is what would be printed if the expression was in 
    an alert statement... for example, for (i) what would get printed for 
    
      alert(true || false)