CS200 Final23
CS200 Final23
Room: ……………………………………………………………………………………………………………………………….
Reminders:
● Duration: 120 minutes.
● There are 18 pages in this exam set. Please check the page numbers before you start to
solve questions.
● This is a closed book exam. You are not allowed to use your own papers, documents,
scripts, etc., nor any electronic equipment (notebook computers, calculators, cell
phones, etc.)
● Note that only answers in page 16 will be evaluated.
1
Select the correct answer (ONLY ONE answer is correct):
HTML
<table>
<tr> <td colspan="3">Cell 1</td> </tr>
<tr> <td>Cell 2</td> <td>Cell 3</td> <td>Cell 4</td> </tr>
</table>
A. They define separate sections of a webpage for header and footer content.
B. <div> is used for styling multiple elements, while <span> is used for styling single element.
C. <div> is used for styling single element, while <span> is used for styling multiple elements.
D. <div> is used to group block-level elements, while <span> is used to group inline elements.
A. It defines a hyperlink.
B. It represents a horizontal rule or line.
C. It specifies a header for a document or section.
D. It creates a new paragraph.
2
5. Given the desired form structure shown below, which code snippet correctly represents the
form?
7. What does the placeholder attribute in the following HTML code snippet do?
3
8. How to define a table row with two cells, where the first cell spans two columns?
10. Which of these options are all valid HTML form tags?
A. <form><header><input>
B. <form><select><meta><option>
C. <form action=... method=...><label><input type=...></form>
D. <label><input><output><button>
4
</select> <br>
<input type="submit" value="Submit">
</form>
5
Page Content Page Content
</body> </html>
</html> </body>
6
CSS
17. Select the rule set to make all the text in your web page blue and centered.
A. p {color: blue;}
B. body {text-align: left; color: blue;}
C. p {text-align: center; color: blue;}
D. body {text-align: center; color: blue;}
A. p { color: red; }
B. p { colour: red; }
C. p-style { color: red }
D. p { color style: red }
20. What is the main difference between flexbox and grid layout in CSS?
A. Flexbox is only used for text-based layouts, while grid layout is for image-based layouts.
B. Flexbox is for one-dimensional layouts, while grid layout is for two-dimensional layouts.
C. Flexbox and grid layout are the same thing.
D. Flexbox is for two-dimensional layouts, while grid layout is for one-dimensional layouts.
21. How can you create a responsive grid layout using CSS grid?
A. Define the grid container and its columns and rows using the 'grid-template-columns' and
'grid-template-rows' properties and use media queries to adjust the layout based on
different screen sizes.
B. Use the 'flexbox' property to create a grid layout.
C. Set the width of each column and row using fixed pixel values.
7
D. Use the 'table-layout' property to define the grid layout.
23. Which CSS selector targets an element when you hover over it?
A. .hover
B. #hover
C. hover()
D. :hover
24. Using Responsive Web Design (RWD) ensures that the site will display correctly in all desktop
browsers and mobile devices. You used a grid-based layout and resize-able images, which is
another RWD technique that you can use in responsive design?
A. Use smaller fonts for all body text, to ensure it will appear correctly on smaller screens.
B. Use static pixels for all content positioning.
C. Use relative units, such as percentages, for positioning page elements.
D. Use standard page structure elements, including <header>, <footer> and <article>, because
older devices will display content in the structure elements correctly.
25. Consider the following HTML and CSS. Which element will have a red border?
HTML CSS
<div class="box"></div> .box { border: 2px solid red; }
<span class="box"></span>
<h2>Title</h2>
<p>Paragraph 1</p>
<p>Paragraph 2</p>
<p>Paragraph 3</p>
h2 ~ p { color: blue; }
8
C. All <p> elements following an <h2>
D. Only the second and third <p> elements
27. Which CSS selector targets the <input> element with the attribute "type" set to "text" inside a
<form> element?
A. form input[type="text"]
B. form > input[type="text"]
C. form input:text
D. form input.text
HTML CSS
.container {
display: flex;
justify-content: space-
<div class="container"> between;
<div class="box"></div> }
<div class="box"></div> .box {
</div> width: 100px;
height: 100px;
background-color: #3498db;
}
A. Two blue boxes stacked on top of each other with equal space between them.
B. Two blue boxes placed side by side with equal space between them.
C. Two blue boxes placed side by side without space between them.
D. Two blue boxes stacked on top of each other without space between them.
.container {
display: grid;
grid-template-columns: 1fr 1fr 1fr ;
grid-gap: 20px;
}
30. Which CSS selector targets the first <p> element inside a <div> element?
9
A. div p:first-child
B. div p:first-of-type
C. div > p:first-of-type
D. div > p:first-child
31. Which CSS selector targets elements with the class "highlight" that are descendants of a <div>
element?
A. div.highlight
B. div .highlight
C. .highlight div
D. div > .highlight
<div>
<p>Paragraph 1</p>
<span>Some other element</span>
<p>Paragraph 2</p>
<p>Paragraph 3</p>
</div>
A. <p>Paragraph 1</p>
B. <p>Paragraph 2</p>
C. <p>Paragraph 3</p>
D. All the <p> elements
33. Which CSS selector targets the <span> elements directly following an <h2> element within a
<div>?
10
JavaScript
34. Complete the code to add an event listener that triggers a function named "handleClick" when
a button with the ID "myButton" is clicked:
document.getElementById("myButton").addEventListener("______",
handleClick);
A. "onClick"
B. "onButtonClicked"
C. "mouseClick"
D. "click"
console.log(array);
A. [2, 3, 6, 5, 10]
B. [1, 4, 3, 6, 5]
C. [2, 3, 6, 5, 12]
D. [1, 3, 5, 7, 9]
A. style.display = "none"
B. hideElement = "none"
C. visibility = "hidden"
D. display = "none"
37. Which is the object on which the event occurred or with which the event is associated?
A. event type
11
B. event target
C. both event type and even target
D. interface
const student = {
name: 'Emma',
age: 25,
grade: 'A'
};
student['grade'] = 'B';
console.log(student.grade);
A. A
B. B
C. undefined
D. This code will throw an error.
function mysteryFunction(w) {
let s = 0;
let e = w.length - 1;
while (s < e) {
if (w[s] !== w[e]) {
return false;
}
s++;
e--;
}
return true;
}
40. Which are the events that have default actions that can be canceled by event handlers?
12
C. Submit and reset events.
D. form-related events
42. Fill in the blanks to set the background color of all elements with the class "section" to yellow:
A. background = "yellow"
B. backgroundColor = "yellow"
C. setStyle("background-color", "yellow")
D. setBackground("yellow")
43. Fill in the blanks to create a new <li> element, set its text content to "Item 1", and append it to
an unordered list with the ID "myList":
13
44. When is the mouseout event fired?
A. d
B. a
C. b
D. c
const person = {
name: 'Lydia',
age: 21,
};
console.log(person);
A. Replaces the content of the element with the ID 'myElement' with the text 'Hello, World!'.
B. Inserts the text 'Hello, World!' as a child node of the element with the ID 'myElement'.
14
C. Creates a new paragraph element with the text 'Hello, World!' and stores it in a variable.
D. Appends a new paragraph element inside the element with the ID 'myElement'.
function checkAge(age) {
if (age < 18) {
const message = "Sorry, you're too young.";
} else {
const message = "Yay! You're old enough!";
}
return message;
}
console.log(checkAge(21));
49. What is the output on the console for the following JavaScript code.
<script>
let x = 'Web Dev';
console.log(typeof x);
x=1;
console.log(typeof x);
</script>
A. string string
B. string number
C. null null
D. string integer
50. Complete the code to attach a "mouseover" event listener to an HTML element with the id
"hoverElement" that triggers a function named "handleHover":
document.getElementById("hoverElement").addEventListener("______",
handleHover);
A. hover
B. mouseover
C. onHover
15
D. mouseEnter
16
17
18