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) ________ create an unnumbered list of items
    
      ii) ________ create a top level header for the page
    
     iii) ________ change the text style to Arial and the color to red
    
      iv) ________ create a button to click to run a JavaScript program
    
       v) ________ cause a line break      
    
      vi) ________ add a new row to a table 
    
     vii) ________ create a line horizontally across the page
    
    viii) ________ insert a block of JavaScript code
    
      ix) ________ skip a line and indent for a new paragraph
    
       x) ________ 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) ________ single datum of binary information: 0 or 1
    
      ii) ________ slow non-volatile storage
    
     iii) ________ basic collection of 8 binary data values
    
      iv) ________ grouping of variable locations in a program that can be systematically 
                   used by subscript
    
       v) ________ place where all arithmetic operations are performed in the computer
    
      vi) ________ 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: _____________________
    
    

  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: ________________
    
    

  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: ________________
    
    
    
    

  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: ________________ 
    
    
    
    
    
    

  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: ________________ 
    
    
    
    
    
    

  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: ________________ 
    
    
    

  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: ________________ 
    
    
    
  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: ________________ 
    
    
    
    
    
    
  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: ________________ 
    
    
    
    
    

  12. (10%) For part of this question, put in the space given the result produced by each function or expression:
       i) ________ true || false
    
      ii) ________ isNaN("midterm");
    
     iii) ________ isNaN(25);
    
      vi) ________ Math.floor(12.98765);
    
       v) ________ Math.round(12.98765);
    
      vi) ________ Math.sqrt(9);
    
     vii) ________ !true
    
    viii) ________ true && false
    
      ix) ________ Number("-225");
     
       x) ________ 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)