Assignment 2 Term 3

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

Quiz (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 y 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 y 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

Programming in JavaScript

  1. Write a program that calculates the following sum: 1+2+22+23+24+25+26+27. Also, write as a comment the answer you get.
  2. 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.
  3. 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.
  4. Write a program that asks the user for the name of 2 items she purchased and the amount of each such items. For instance, say you purchased 1 laptop and 2 notebooks, your program first asks "What did you buy", you answer "laptop", then it asks "How many laptop did you buy and you say "1"; then your program asks again "What else did you buy", your say "Notebook", and your program asks then "How many notebooks did you buy" and your say "2". Then your program needs to print on one line "Laptops" then some ten spaces and then "Notebooks"; in the next line, right under Laptops your program must write 1, and right under Notebooks it must write 2.