Dragon Academy

G9 Exploring Computer Technology

Term 4 Test

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

Grading: All questions and problems weigh the same towards the final grade. For example, having 7 correct answer gives you a grade of 50%; having 10 correct answers gives you a grade of 71%; 12 correct answers, a 86%; 13 correct answers, 93%, and 14 correct answers is a 100% mark.

Note: Make sure to resize the text boxes so that they completely show your answers.

Warning: Do not reload the page. Do not go back. If you reload this page or go back you will loose all your answers and will have to start over again!


Additioanl notes on comparisons

We have seen how to compare numbers, like x<=3, z>x+y. We can use the larger-than, >, and smaller-than, <, in order to compare strings. The comparison is done by alphabetical order.

Follow these examples in order to answer the questions below.

Questions (K|C|A)

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

  1. What will be shown by the following code fragment
    
    var x = 2 ;
    var y = 2 ;
    if ( x > y ) { 
    	alert("True") ;
    }
    else {
    	alert("False") ;
    }
    
    					
    True
    False
    None
    Will print an error message
  2. What will be shown by the following code fragment
    
    var x = "Monday" ;
    var y = "Monday" ;
    if ( x == y ) {
    	alert("True") ;
    } else {
    	alert("False") ;
    }
    
    					
    True
    False
    None
    Will print an error message
  3. 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
  4. What will be shown by the following code fragment
    
    var x = 3 ;
    if ( x == 2 ) {
    	alert("True") ;
    }
    
    					
    True
    False
    Nothing
    Will print an error message
  5. 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) ;
    
    						
  6. 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) ;
    
    						
  7. 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) ;
    
    						
  8. 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
  9. Select the values of x for which the following code will produce the value "No". There may be more than one correct choice.
    
    						function choose(x){
    							if ( x < 5) || x > 90) {
    							 return "yes";
    							}
    							else {
    							 return "No" ;
    							}
    						}
    						alert( choose(y) ) ;
    						
    						
    3
    5
    10
    100
  10. 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
  11. what name will this code show?
    
    var name1 = "John" ;
    var name2 = "Donald" ;
    var x = 30 ;
    var person = "unknown"; 
    
    if ( name1 < name2 ) {
     person = name1 ;
    }
    else if (x > name2) {
     person = name2 ;
    }
    alert( person ) ;
    
    						
    John
    Donald
    unknown
    x

Programming in JavaScript

Note: Make sure to resize the text boxes so that they completely show your answers.

  1. Write a program that calculates the following sum: 1+2+3+...+137 using a while loop. Also, write as a comment the answer you get.
  2. Write a program that calculates the following sum using a while loop:
    -2-1+1+2+3+4+5+6+7+8+9+10
    Note: you cannot just assign this expression or print it as it is. Also, write as a comment the answer you get.
  3. 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.
  4. 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.
  5. 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 nor add anything and all text below must be used in the final program
  6. Write a program that prompts the user to guess a number. If it is correct, show a dialog (alert) 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 and store it in a variable called x.
  7. 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.
  8. 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.