Midterm Solution PDF
Midterm Solution PDF
EXAMINATION
FALL 2016
AUTHORIZED MEMORANDA :
Randy Connolly and Ricardo Hoar, Fundamentals of Web Development,
Pearson 2015, ISBN-10: 0-13-340715-2, ISBN-13: 978-0-13-340715-0
Students MUST count the number of pages in this examination question paper before beginning to
write, and report any discrepancy to a proctor. This question paper has x pages + cover
page = _x__ pages in all.
This examination question paper may not be taken from the examination room.
Name:
Student Number:
Exam questions will not be explained, and no hints will be given. If you think that something is unclear or ambiguous,
make a reasonable assumption (one that does not contradict the question), write it at the start of the solution, and answer
the question. Do not ask questions unless you believe you have found a mistake in the exam paper. If there is a mistake,
the correction will be announced to the entire class. If there is no mistake, this will be confirmed, but no additional
explanation of the question will be provided.
Question 1: HTML and CSS (10 marks)
Answer (1 mark): b
Answer (1 mark): b
Answer (1 mark): c
4. Choose the preferred tag pair to use when displaying important text in bold font.
a. <bold>…</bold>
b. <strong>…</strong>
c. <big>…</big>
d. none of the above
Answer (1 mark): b
Answer (1 mark): c
6. Cascading Style Sheet rules are comprised of:
a. Selectors and Declarations
b. Properties and Declarations
c. Selectors and Attributes
d. None of the above
Answer (1 mark): a
7. When CSS is coded in the body of the web page as an attribute of an HTML tag it is called
________.
a. Embedded
b. Inline
c. External
d Imported
Answer (1 mark): b
Answer (1 mark): d
9. To apply a style to a certain group of elements on a web page, configure a CSS _____________.
a. group
b. id
c. class
d. None of the above
Answer (1 mark): c
10. Select the code below that uses CSS to configure an id named “footer” that configures small,
italic text.
a. #footer { font-size: small; font-weight: italic;}
b. .footer{ font-size: small; font-weight: italic;}
c. .footer { font-size: small; font-style: italic;}
d. #footer { font-size: small; font-style: italic;}
Answer (1 mark): d
Question 2: Forms and Tables (10 marks)
Create a simple HTML document that creates a table as shown in the figure below.
<!DOCTYPE html>
<html lang = "en">
<head>
<title> Midterm Question </title>
<script type = "text/javascript" src = "midterm.js" >
</script>
</head>
<body>
<h1> Choose your favorite color </h1>
<form id = "colorsForm">
<p>
<label> <input type = "radio" name = "colorButton" value = "red" /> Red</label>
</p>
<p>
<label> <input type = "radio" name = "colorButton" value = "blue" /> Blue </label>
</p>
<p>
<label> <input type = "radio" name = "colorButton" value = "green" /> Green</label>
</p>
<p>
<label> <input type = "radio" name = "colorButton" value = "yellow" /> Yellow</label>
</p>
<p>
<label> <input type = "radio" name = "colorButton" value = "orange" /> Orange</label>
</p>
</form>
</body>
</html>
Window.onload = function() {
var dom = document.getElementById("colorsForm");
dom.elements[0].onclick = colorChoice;
dom.elements[1].onclick = colorChoice;
dom.elements[2].onclick = colorChoice;
dom.elements[3].onclick = colorChoice;
dom.elements[4].onclick = colorChoice;
}
function colorChoice () {
var color;
// Put the DOM address of the elements array in a local variable
var radioElement = document.getElementById("colorsForm").elements;
// Determine which button was pressed
for (var index = 0; index < radioElement.length; index++) {
if (radioElement[index].checked) {
color = radioElement[index].value;
break;
}
}
a) A document’s DOM tree represents all of the nodes in a document, as well as their
relationships to each other.
Answer (2 marks): False. Every element is represented by a DOM node. Each node
is a member of the document’s DOM tree.
Answer (2 marks): False. The document is the root node, therefore has no parent
node.
e) The createElement method creates a new node and inserts it into the document.
Answer (2 marks): False. The createElement method creates a node, but does not
insert it into the DOM tree.
f) The insertBefore method is called on the document object, taking a new node and an existing
one to insert the new one before.
Answer (1 mark): d
<?php
$states = array("Canada" => array( "population" => "35,000,000", "capital" => "Ottawa"),
"France" => array( "population" => "64,600,000", "capital" => "Paris")
"Germany" => array( "population" => "82,600,000", "capital" => "Berlin") );
echo "population=" . $states["France"]["population"] . " capital=" . $states["Germany"]["capital"];
?>
<?php
$abc = 100;
echo 'Value of abc = $abc';
?>
Answer (1 mark): e
4. What will be the output of the following PHP code?
<?php
$abc = 10;
function calculate($param) {
return $param + $abc;
}
echo calculate(30);
?>
a) 10
b) 20
c) 30
d) 40
e) 3010
Answer (1 mark): d
NOTE: actually there will be an error/warning raised, as $abc is NOT in scope within
calculate. So to return 40, we would need to add a line “global $abc;” before the return
statement. So I will accept 30 as a proper answer as well.
5. Which one of the following is the correct PHP to output a message to a web page:
a) Echo "Hello";
b) echo "hello"
c) echo 'hello';
d) echo hello;
e) none of the above
Answer (1 mark): c
NOTE: at least c was the expected answer. It turns out that a or b would also work: keywords
in PHP are not case sensitive, and you can ignore the ; particularly when the statement is the
last one.
6. When we say that PHP variables are “dynamically typed” we mean that
a) PHP variables operate your keyboard for you
b) It doesn’t matter where the PHP code is typed on the page
c) A variable type can be an integer, then later a string, and then later an object (for instance)
d) A variable type cannot be changed after a variable is initialized
e) PHP variable processing happens sequentially
Answer (1 mark): c
7. Write an HTML document that includes an anchor tag that calls a PHP document called
greeting.php. Also write the called PHP document which returns a randomly chosen
greeting from a list of five different greetings. The greetings must be stored as constant strings
in the script. A random number between 0 and 4 can be computed by invoking the function
rand(0, 4)
Answer (4 marks):
HTML Document:
<!DOCTYPE html>
<html lang = "en">
<body>
<a href = "greeting.php"> Please give me a greeting </a>
</body>
</html>
greeting.php:
<!DOCTYPE html>
<html lang = "en">
<head>
<title> Random Greeting</title>
<meta charset = "utf-8" />
</head>
<body>
<?php
$greetings = array("Hello!", "Hej!", "Hallo!", "Hola!",
"Bonjour!");
$sub = rand(0, 4);
print "$greetings[$sub]";
?>
</body>
</html>