Dragon Academy

G9 Exploring Computer Technology (TEJ0)

2019 Exam

Name: Surname: Date: . Save your answered form as a PDF file with name "Exam.pdf" and submit it as an attachment via Email to msantos@dragonacademy.org.

This test consists in two parts: a quiz with questions and a coding part with 4 problems. All, questions and problems, weigh the same towards the final mark.

Quiz (K|C|A)

Write your answer in the corresponding textboxes or choose the rigth radio buttons/checkboxes.

  1. Write a webpage with the following requirements
    • The title must be "Exam"
    • The body contains 3 headings:
      1. The largest possible goes at the top and says "G9 Exam 2019"
      2. The second heading is a bit smaller than the first and says "Text"
      3. The last heading is as large as the second and says "Media"
    • Under the first heading write 2 paragraphs:
      • The first says: "This is paragraph 1" and the word paragraph is in boldface
      • The second says: "This is a second paragraph" and the word second is emphasized, i.e., is in italics
    • Under the media heading do the following:
      • Write a text that says "G9 CS slides" and make it a link pointing to the URL http://msantos.sdf.org/G9
      • Insert the picture with URL http://msantos.sdf.org/G9/MZ.png
  2. Determine if the following Turing machine will halt or not. It starts in state I reading the first character on the left of a tape with content "010010001000..." The trailing dots means the rest of the tape contains only 0s. The rules are below.
  3. Write the name of the following gate and write down its truth table. Label the input lines x and y and the output line z.
  4. Write the name of the following gate and write down its truth table. Label the input lines x and y and the output line z.
  5. Write the name of the following gate and write down its truth table. Label the input lines x and y and the output line z.
  6. What will be shown by the following code fragment
    						
    						var x = 7 ;
    						var y = 2 ;
    						if ( x == y ) { 
    							alert("True") ;
    						}
    						else {
    							alert("False") ;
    						}
    						
    					
    True
    False
    Nothing
    Will print an error message
  7. What will be shown by the following code fragment
    
    var x = "Monday" ;
    var y = "Sunday" ;
    if ( x < y ) {
    	alert("True") ;
    } else {
    	alert("False") ;
    }
    
    					
    True
    False
    None
    Will print an error message
  8. What will be shown by the following code fragment
    					
    						var x = 2 ;
    						if ( x != 2 ) {
    							alert("True") ;
    						}
    					
    					
    True
    False
    Nothing
    Will print an error message
  9. What will be shown by the following code fragment
    
    var x = 3 ;
    if ( x == 3 ) {
    	alert("True") ;
    }
    
    					
    True
    False
    Nothing
    Will print an error message
  10. Enter the value that will be shown by the following code fragment.
    
    x = 3 ; 
    y = 10 ;
    if (x > 0){
       y = 12;
    } else if ( x > 1) {
       y = y + 5 ;
    } else {
       y = 7 ;
    }
    alert(y) ;
    
    						
  11. Enter the value that will be shown by the following code fragment.
    
    x = -3 ;
    y = 10 ;
    if (x > 0){
       y = 12 ;
    }
    y = y + 5 ;
    alert(y) ;
    
    						
  12. Enter the value that will be shown by the following code fragment.
    
    x = -3 ;
    y = 10 ; 
    if ( x > 0 ) {
       y = 12 ;
       y = y + 5 ;
    }
    alert(y) ;
    
    						
  13. Select the values of x for which the following code will produce the value "yes". There may be more than one correct choice.
    
    if ( ! (x < 5) ) {
     alert("yes") ;
    }
    else {
     alert("No") ;
    }
    
    						
    3
    5
    10
    50
  14. Select the values of x for which the following code will produce the value "No". There may be more than one correct choice.
    
    							if ( x < 5 || x > 90) {
    							 alert( "yes") ;
    							}
    							else {
    							 alert("No") ;
    							}
    						
    						
    3
    5
    10
    100
  15. what name will this code show?
    
    var name1 = "John" ;
    var name2 = "Donald" ;
    var x = 30 ;
    var person = "unknown"; 
    
    if ( name1 < name2 ) {
     person = name1 ;
    }
    else {
     person = name2 ;
    }
    alert( person ) ;
    
    						
    John
    Donald
    unknown
    x
  16. How many times will this loop print the text "again"?
    
    for( var i = 0 ; i < 10 ; i++) {
      print("again")
    }
    
    						
    8
    10
    None
    9
    Infinite
  17. How many times will this loop print the text "Hello World"?
    
    var i = 2
    while ( i < 10 ){
      print("Hello World")
    }
    
    						
    8
    10
    None
    9
    Infinite

Programming in JavaScript

  1. Write the javascript code that assigns the number 2019 to the variables year, your name to the variable name and then shows an alert with the message "I am ____ and I passed my G9 CS course from ______", where the first blank must show the string in name and the second must show the number in the variable year.
  2. Write a program that asks the user for a number. Assign that number to the variable x. Then show an alert with the message Your number + 137 is equal to ____, where the blank space must contain the sum of 137 plus the number introduced by the user.
  3. Write a loop that repeats 3 times. In each iteration it must print the text "Iteration ____" where the blank space must be the iteration number starting by 1 for the first iteration.
  4. Write a program that asks the user for a number, it assigns it to a variable called N, and then calculates the following sum: 1+2+3+...+N. Also, write as a comment the answer you get when the user inputs 137.
  5. Write a program that calculates the following sum: 0 + 20+ 2*21+ 3*22+ 4*23+ 5*24+ 6*25. Also, write as a comment the answer you get.
  6. Write a program that calculates the following product: 1*2*1/3*4*1/5*6*1/7*...*1/19*20. Also, write as a comment the answer you get. Notice: You must use only one while-loop. Yet there are different ways to solve this problem.
  7. Somebody scrambled our code. Reorder the different lines of code shown here so that you end up with a program that shows in order the following messages: "Happy birthday to you" (twice), "Happy birthday dear Julia", "Happy birthday to you". Notice: You cannot remove anything and all text below must be used in the final program
  8. Write a program that prompts the user to guess a number. If it is correct, show a dialog window with the message "Correct!". If the guess is not right, show a dialog box with the message "Sorry. Incorrect guess.". You have to choose the hidden number yourself.
  9. Write a program that prompts the user to guess a number. This time we will give the user 3 posibilities to guess it right. At any time, if the guess is correct, show a dialog window saying so. If a guess is larger than the hidden number the program must show a dialog box saying "It's smaller!"; if a guess is smaller than the right number, the program must print "It's larger!". If after the third try the guess is not right, show a dialog box with the message "Game over.". You have to choose the hidden number yourself.