Final Exam Fall 2008

Final Exam Fall 2008

<p>Name: ______Section: ______</p><p>Final Exam – Fall 2008</p><p>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!</p><p>(1) Write the code needed to comment in HTML:</p><p>Answer: ______</p><p>(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. ______</p><p>2. ______</p><p>(1) Examine the following code: <script language="JavaScript"> function foo() { alert("Hello"); }</p><p>Answer: ______</script></p><p>In the line above (above the </script> tag), write the JavaScript (not HTML!) code that will invoke the function ‘foo’. </p><p>(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:</p><p>Answer: ______</p><p>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). ______</p><p>______</p><p>(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.</p><p>(1) What would be the output of the following: document.write(5 + “10”); </p><p>Answer: ______</p><p>2 (1) Examine the following code: var x; x = “hello”;</p><p>What is the data type stored inside the variable x ?</p><p>Answer: ______</p><p>(1) What is wrong with the following code? var x; alert(x); Answer: </p><p>______</p><p>(1) What is the scope of the variable x in the following code? <script language="JavaScript"> function foo() { var x = 5; document.write(x); } </script></p><p>Answer: ______</p><p>(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). <script language="JavaScript"> function foo() { var name; name = document.form1.txtFirstName.value; document.write(“name”); } </script> Answer: </p><p>______</p><p>3 (1) Which one of the following variable names is illegal, and why? var x, name2, 3name, veryVeryLongVariableName; Answer: </p><p>______</p><p>(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: ______</p><p>(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: ______</p><p>(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? <script language="JavaScript"> function foo1() { prompt("How old are you?"); } </script> Answer: ______</p><p>______</p><p>(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: ______</p><p>______</p><p>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: ______</p><p>______</p><p>(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: ______</p><p>(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?</p><p>Answer: ______</p><p>(1) Demonstrate how you would apply this style. (Hint: The property used to change the text color in a style is called ‘color’) Answer: ______</p><p>______</p><p>5 (5 - total) In the box below, write an external style sheet that does the following: 1. Changes the style of the <body> tag. You must apply at least 2 styles to the tag. 2. Changes the style of the <h2> tag. Again, apply at least 2 styles - Hint: Be careful not to add any tags or other code that should not be there!</p><p>- Write an appropriate filename for this page: Answer: ______</p><p>- Write the tag that you would use in an HTML document to link to this page. Answer: ______</p><p>______</p><p>- Where in your HTML document should you place this tag? Answer: ______</p><p>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 <script> tags - If you run out of space, you may use the backside of this page</p><p>(2) Write some JavaScript code that will check to see if the user wishes to visit Los Angeles. If they are, write an alert box that says: “Enjoy Hollywood!”</p><p>(3) Write some code that will examine the number of days the user wishes to travel. - If they are travelling 6 or fewer days output (alert or document.write): “Regular rates apply.” - Fewer than 13 days, output “You get the 1-week discount”. - 14 or more days, output: “You get the 2-week special discount”.</p><p>7 8 Figure 1 – RESERVATIONS</p><p>9</p>

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    9 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us