Final Exam Fall 2008
Total Page:16
File Type:pdf, Size:1020Kb
Name: ______Section: ______
Final Exam – Fall 2008
The numbers in parentheses are the points value for each question. Note: There is no penalty for wrong answers. If you’re not sure, guess!
(1) Write the code needed to comment in HTML:
Answer: ______
(2) Write the code for the two different ways of commenting in JavaScript: Note: You do not need to describe the differrences between them. 1. ______
2. ______
(1) Examine the following code:
In the line above (above the tag), write the JavaScript (not HTML!) code that will invoke the function ‘foo’.
(1) Give one example of a reserved keyword (i.e. a word that you could not use as a variable name because it is reserved) in JavaScript:
Answer: ______
1 (1) Using document.write, write a line of JS code that will create a hyperlink to DePaul’s web site. (ie: the text DePaul University should be clickable). ______
______
(2) Assume an HTML page with a form called ‘form1’ that has a a textbox called ‘txtNum’. Write a JS function that will output the square-root of that number. You can output the numeric result inside an alert box. (You don’t need to add any additional text. ) To do the calculation, recall that there is a built in JS function called Math.sqrt( ) that calculates square roots.
(1) What would be the output of the following: document.write(5 + “10”);
Answer: ______
2 (1) Examine the following code: var x; x = “hello”;
What is the data type stored inside the variable x ?
Answer: ______
(1) What is wrong with the following code? var x; alert(x); Answer:
______
(1) What is the scope of the variable x in the following code?
Answer: ______
(2) Why will this function not run as intended? You may assume that the HTML is all correct (ie. You may assume that there is a form called form1 and a textbox called txtFirstName). Answer:
______
3 (1) Which one of the following variable names is illegal, and why? var x, name2, 3name, veryVeryLongVariableName; Answer:
______
(1) What is the first operation that will be executed in the following line of code? (Assume all variables have been declared). Answer this question (and the next one) by writing the operation that you think will be executed first: e.g. b-10 or a+5 etc result = a+b+10 / 2-11; Answer: ______
(1) What is the first operation that will be executed in the following line of code? (Assume all variables have been declared). position = (a + 5 * c) * (b - 10); Answer: ______
(1) Recall the built-in JavaScript function called prompt() that will ask the user a question and will return the value entered by the user. Examine the following code. Why is this code ineffective? Answer: ______
______
(1) Examine the following code: x = x * 2; In standard algebra, this line may cause confusion as you have a variable on both sides of the equals sign. Why is this line not a problem in JavaScript? Answer: ______
______
4 (1) True or False: The following code will run without problem in JavaScript function foo() { var y; y = 4; alert(y); } Answer: ______Bonus (1): Whether you answered true or false, explain what is wrong/unacceptable with the above: ______
______
(1) What will the alert statement output in the following code? function foo() { var x = 5, y = 20; if (x > 10 || y < 10) { alert("A"); } else if (x > 10 || y > 30) { alert("B"); } else if (x < 10 || y < 30) { alert("C"); } else { alert("D"); } } Answer: ______
(1) Imagine that you are typing the following in an HTML page: The red fox jumped over the fence. You wish to alter the style of the word ‘red’ in the sentence using CSS. You want to alter the word so that it appears colored red on the web page. Of the 3 different CSS styles discussed in class, which would be most appropriate to change a single word in a sentence?
Answer: ______
(1) Demonstrate how you would apply this style. (Hint: The property used to change the text color in a style is called ‘color’) Answer: ______
______
5 (5 - total) In the box below, write an external style sheet that does the following: 1. Changes the style of the
tag. You must apply at least 2 styles to the tag. 2. Changes the style of thetag. Again, apply at least 2 styles - Hint: Be careful not to add any tags or other code that should not be there!
- Write an appropriate filename for this page: Answer: ______
- Write the tag that you would use in an HTML document to link to this page. Answer: ______
______
- Where in your HTML document should you place this tag? Answer: ______
6 Use the attached image Figure I - “Reservations” to answer the next two questions. The names of the form elements are all printed on the drawing. Assume that the form is named form1 . For these questions you only need to write the relevant code. That is: - You do NOT need to place the code inside a function - You do NOT need to include