CS202 – Fundamentals of Front End Development: Midterm Important Subjective (35 Solved Q&As)
Computer Science • Read every solved subjective question with its model answer directly on this page. Free, no login required.
All 664 Midterm Packs · CS202 Course Page · CS202 MCQ Pack (145 MCQs)
-
H2O is given as text and you have to write 2 as subscript. How will you write it in HTML?
Topic: HTML Basics, Lists & Text Formatting
To write H2O with the "2" as a subscript, you can use HTML formatting as follows: H<sub>2</sub>O This will display "H■O" with the "2" subscripted.
-
Write the output of the following code: <html> <body> <h2> HTML List</h2> <ul> <li>Coffee</li> <li>Tea</li> <li>Milk</li> </ul> </body> </html>
Topic: HTML Basics, Lists & Text Formatting
HTML List • Coffee • Tea • Milk (The <h2> heading "HTML List" is displayed first, followed by a bulleted (unordered) list of Coffee, Tea and Milk.)
-
What are the types of lists in HTML?
Topic: HTML Basics, Lists & Text Formatting
In HTML, there are three main types of lists: • Ordered List (<ol>) • Unordered List (<ul>) • Description List (<dl>)
-
Differentiate between Div and Span.
Topic: HTML Basics, Lists & Text Formatting
<div> (Division): The <div> element is a block-level element, meaning it typically starts on a new line and takes up the full width available. It is used to group together HTML elements and create divisions or sections within a web page. <div> elements are often used to structure the layout of a webpage, such as defining sections, sidebars, headers, footers, etc. It is commonly styled with CSS to control its appearance, layout, and positioning. Examples: <div id="header">, <div class="sidebar">, <div class="container">. <span> (Inline Span): The <span> element is an inline-level element, meaning it does not start on a new line and only takes up as much width as its content requires. It is used to apply styles to a specific portion of text or content within a larger block of text. <span> elements are often used to apply CSS styles, such as color, font size, font weight, etc., to individual words or phrases within a paragraph. It does not affect the layout of the document and is typically used for small-scale styling or scripting purposes. Examples: <span class="highlight">, <span style="color: red;">.
-
Create a form in HTML of student name and roll number.
Topic: HTML Forms
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Student Information Form</title> </head> <body> <h2>Student Information Form</h2> <form action="#" method="POST"> <label for="studentName">Student Name:</label><br> <input type="text" id="studentName" name="studentName"><br><br> <label for="rollNumber">Roll Number:</label><br> <input type="text" id="rollNumber" name="rollNumber"><br><br> <input type="submit" value="Submit"> </form> </body> </html>
-
How to convert HTML code to XHTML? Write 4 points.
Topic: XHTML & Code Comments
To convert HTML code to XHTML: • Add an XML declaration (<?xml version="1.0" encoding="UTF-8"?>). • Replace the HTML doctype with an XHTML doctype. • Ensure all elements have proper closing tags. • Quote all attribute values using double quotes.
-
Why do we use comments?
Topic: XHTML & Code Comments
Comments in markup languages like HTML serve to enhance code readability and understanding. They act as documentation, clarify complex sections, aid debugging, facilitate communication within teams, and enable temporary code adjustments without deletion. Overall, they are essential for code maintenance and collaboration.
-
Write the code in CSS for a table with border 1px and background color should be green.
Topic: CSS Styling • 3 marks marks
table { border: 1px solid black; /* 1px solid black border */ background-color: green; /* Green background color */ }
-
Write the syntax of comments in JavaScript.
Topic: JavaScript Basics
Single-line Comments: // This is a single-line comment Multi-line Comments: /* This is a multi-line comment */
-
Define URL.
Topic: Web Fundamentals
A URL (Uniform Resource Locator) is a reference to a web resource that specifies its location and, optionally, a protocol for accessing it. It serves as a standardized way to identify resources on the internet. The following questions are NOT from any past paper. They were created from the topics that recur most often in the MCQ sources for this course (see the header disclosure), and each is given with a model answer.
-
Write the basic structure of an HTML5 document and briefly explain each part.
Topic: HTML Structure & Elements • 5 marks marks
<!DOCTYPE html> <html> <head> <title>Page Title</title> </head> <body> Page content goes here. </body> </html> • <!DOCTYPE html> — declaration that tells the browser this is an HTML5 document; it must be the very first line. • <html> — the root element that wraps the whole document. • <head> — contains information about the document (metadata) that is not displayed, such as the title and links to CSS. • <title> — defines the title of the document, shown in the browser tab. • <body> — contains all the visible content of the web page (headings, paragraphs, images, links, etc.).
-
Differentiate between block-level elements and inline elements in HTML. Give two examples of each.
Topic: HTML Structure & Elements • 3 marks marks
Block-level elements: • Always start on a new line and take up the full width available. • They are used to structure the main parts of a page. • Examples: <div>, <p>, <h1>, <ul>. Inline elements: • Do not start on a new line; they take only as much width as their content needs. • They are used inside a line of text/content for formatting or styling a small portion. • Examples: <span>, <a>, <b>, <img>.
-
What are the rowspan and colspan attributes in an HTML table? Write a small table code in which one cell spans two columns.
Topic: HTML Structure & Elements • 3 marks marks
• colspan specifies the number of columns a cell should span (merge horizontally). • rowspan specifies the number of rows a cell should span (merge vertically). Example: <table border="1"> <tr> <th colspan="2">Student Information</th> </tr> <tr> <td>Name</td> <td>Ali</td> </tr> </table> Here the heading cell "Student Information" spans both columns of the table.
-
Write the HTML code to: (a) create a hyperlink to https://www.vu.edu.pk that opens in a new tab, and (b) insert an image named logo.png with the alternate text "VU Logo".
Topic: HTML Structure & Elements • 3 marks marks
(a) Hyperlink opening in a new tab (target="_blank"): <a href="https://www.vu.edu.pk" target="_blank">Virtual University</a> (b) Image with alternate text (the alt attribute is shown if the image cannot be displayed): <img src="logo.png" alt="VU Logo">
-
What is CSS? Write the three ways to add CSS to an HTML page, with one example of each.
Topic: CSS Styling • 5 marks marks
CSS (Cascading Style Sheets) is the language used to describe how HTML elements are to be displayed — their colors, fonts, sizes, layout and positioning. There are three ways to add CSS: 1. Inline CSS — using the style attribute inside an HTML element: <p style="color: red;">Text</p> 2. Internal CSS — using a <style> element inside the <head> section of the page: <style> p { color: red; } </style> 3. External CSS — using a <link> element to link an external .css file inside the <head> section: <link rel="stylesheet" href="styles.css">
-
Differentiate between the id selector and the class selector in CSS, with the syntax of each.
Topic: CSS Styling • 3 marks marks
id selector: • Selects one unique element whose id attribute matches; an id can be used only once on a page. • It is defined with a hash (#) character. • Example: #header { color: blue; } applies to <div id="header">. class selector: • Selects all elements with the given class attribute; the same class can be used on many elements. • It is defined with a period (.) character. • Example: .highlight { color: red; } applies to every element with class="highlight".
-
Explain the four CSS position values: static, relative, absolute and fixed.
Topic: CSS Styling • 5 marks marks
• static — the default position. The element follows the normal flow of the page and is not affected by top/bottom/left/right properties. • relative — the element is positioned relative to its normal (original) position; setting top/left moves it from where it would normally be, without affecting other elements. • absolute — the element is positioned relative to its nearest positioned ancestor (or the page if none) and is removed from the normal flow, so it can overlap other elements. • fixed — the element is positioned relative to the browser window and does not move even if the page is scrolled.
-
What is the difference between "visibility: hidden" and "display: none" in CSS?
Topic: CSS Styling • 2 marks marks
• visibility: hidden — the element is hidden (not visible), but it still takes up its space in the layout of the page. • display: none — the element is completely removed from display and takes up no space, as if it did not exist on the page.
-
Write any five rules for naming variables in JavaScript.
Topic: JavaScript Programming • 3 marks marks
1. Variable names can contain letters, digits, underscores (_) and dollar signs ($). 2. A variable name must begin with a letter, underscore (_) or dollar sign ($) — it cannot begin with a number. 3. Variable names are case sensitive (age and Age are different variables). 4. A variable name cannot contain spaces; multiple words are joined, e.g. using camelCase like firstName. 5. Reserved words (keywords) of JavaScript, such as var, function or return, cannot be used as variable names.
-
Differentiate between the == and === operators in JavaScript, with examples.
Topic: JavaScript Programming • 3 marks marks
• == (equality operator) compares only the values of two operands; it converts the operands to a common type before comparison. Example: 1 == "1" returns true. • === (strict equality operator) compares both the value and the data type of the operands; no type conversion is done. Example: 1 === "1" returns false, because one is a number and the other is a string.
-
Write the value returned by each of the following JavaScript expressions: (a) Math.ceil(7.4) (b) Math.round(8.4) (c) Math.floor(7.9) (d) Math.max(5.2, -5.2, 6.2, -6.2)
Topic: JavaScript Programming • 3 marks marks
(a) Math.ceil(7.4) = 8 — ceil rounds a number up to the nearest integer. (b) Math.round(8.4) = 8 — round gives the nearest integer (0.5 and above round up). (c) Math.floor(7.9) = 7 — floor rounds a number down to the nearest integer. (d) Math.max(5.2, -5.2, 6.2, -6.2) = 6.2 — max returns the largest of the given numbers.
-
How can an array be created in JavaScript? Explain the pop() and sort() functions with examples.
Topic: JavaScript Programming • 3 marks marks
An array is created with square brackets, for example: var students = ["Ali", "Ahmed", "Sara"]; • pop() — removes the last element of an array (and returns it). Example: students.pop(); removes "Sara". • sort() — sorts the elements of an array (by default in alphabetical/ascending order). Example: students.sort(); arranges the names in alphabetical order.
-
Differentiate between the GET and POST methods used to send data to a server.
Topic: Web Technologies: HTTP, XML, AJAX & jQuery • 3 marks marks
GET: • Requests data from a specified resource. • Data is sent in the URL, so it is visible and its length is limited. • Requests can be cached by the client and bookmarked. POST: • Sends data to the server in the body of the request, not in the URL. • There is no practical limit on the amount of data, and the data is not visible in the address bar. • Requests are not cached and cannot be bookmarked.
-
Write any four naming rules for XML elements.
Topic: Web Technologies: HTTP, XML, AJAX & jQuery • 3 marks marks
1. Element names can contain letters, numbers and other characters (such as underscore). 2. Element names cannot start with a number or punctuation character. 3. Element names cannot start with the letters xml (or XML, Xml, etc.). 4. Element names cannot contain spaces. (Also note: XML element names are case sensitive, so <Name> and <name> are different elements.)
-
What is AJAX? What is the role of the responseText property?
Topic: Web Technologies: HTTP, XML, AJAX & jQuery • 3 marks marks
AJAX (Asynchronous JavaScript and XML) is a technique for updating parts of a web page with data from the server without reloading the whole page. It uses the XMLHttpRequest object to send and receive data in the background (asynchronously). The responseText property holds the response data received from the server as a text string; the JavaScript code reads this string and uses it to update the page content.
-
What is jQuery? What is the purpose of the $(document).ready() function?
Topic: Web Technologies: HTTP, XML, AJAX & jQuery • 3 marks marks
jQuery is a fast, small and feature-rich JavaScript library that simplifies HTML document traversing and manipulation, event handling and animation. Its selectors start with the $ sign. The $(document).ready() function allows us to execute a function when the document (DOM) is fully loaded and ready to be worked with, so the script does not run before the page elements exist: $(document).ready(function() { // code to run when the page is loaded });
-
How many parts does a URL have? Define each part in detail.
Topic: Web Fundamentals
A URL (Uniform Resource Locator) is made up of the following parts: • Protocol (Scheme): e.g. http:// or https:// — it tells the browser how to access the resource. • Host / Domain Name: e.g. www.vu.edu.pk — the address of the server where the resource is stored (www is the subdomain). • Port: an optional number, e.g. :80 — the communication port on the server used for the connection. • Path: e.g. /lectures/cs202.html — the location of the file or folder on the server. • Query String: an optional part beginning with "?" — it passes data to the server as key=value pairs joined by "&". • Fragment (Anchor): an optional part beginning with "#" — it points to a specific section within the page.
-
Write six characteristics of a Dynamic URL.
Topic: Web Fundamentals
1. It is generated dynamically by a web application, usually from a database, when a user requests the page. 2. It contains a query string beginning with "?" that carries parameters as name=value pairs joined by "&". 3. It contains special characters such as ?, &, =, % and +. 4. Its content changes according to the user, the session or the search criteria. 5. It is usually long and difficult to read, remember and type manually. 6. It is less friendly for search engines and for bookmarking than a static URL.
-
Write about CSS selectors.
Topic: CSS Styling
A CSS selector is the part of a CSS rule that selects (targets) the HTML element or elements to which the styles will be applied. The main types of selectors are: • Element (Type) Selector: selects all elements of a given tag, e.g. p { color: blue; } • id Selector: selects the single element having a specific id; it is written with a # sign, e.g. #header { } • Class Selector: selects all elements having a specific class; it is written with a dot, e.g. .green { } • Universal Selector: selects every element on the page; it is written as * { } • Group Selector: applies the same style to several selectors separated by commas, e.g. h1, h2, p { } • Descendant Selector: selects elements that are inside another element, written with a space, e.g. div p { }
-
Name the selector used for selecting all h1 elements, and name the selector which can select all of the elements on a page.
Topic: CSS Styling
All h1 elements are selected with the element (type) selector, written simply as the tag name: h1 { } All elements on the page are selected with the universal selector, written as an asterisk: *{} For example, * { color: green; } applies the style to every element. (Elements having class="green" in the HTML are selected with the class selector .green { }.)
-
Write three different ways to use the border-color property in CSS.
Topic: CSS Styling
The value of the border-color property can be given in three different ways (all three examples below set the same red color): 1. By color name: border-color: red; 2. By HEX value: border-color: #FF0000; 3. By RGB value: border-color: rgb(255, 0, 0);
-
A font size of 32 pixels is equal to how many em?
Topic: CSS Styling
The em is a relative unit of measurement equal to the current font size. Taking the standard default base font size of 16 pixels, 1em = 16px, therefore: 32px ÷ 16px = 2em So a font size of 32 pixels is equal to 2em.
-
Write the code to create an image element with image source "VU.jpg", such that when the user clicks on the image, the user is directed to a new page to the URL vu.edu.pk.
Topic: HTML Structure & Elements
<a href="https://www.vu.edu.pk" target="_blank"> <img src="VU.jpg" alt="Virtual University"> </a> Wrapping the <img> element inside an <a> (anchor) element makes the image clickable like a hyperlink, and the target="_blank" attribute opens the linked page in a new page/tab when the image is clicked.
-
Write short details of the window.open(), window.close(), window.moveTo() and window.resizeTo() methods — what does each function do?
Topic: JavaScript Programming
• window.open(): opens a new browser window or tab and loads the specified URL in it; the URL, window name and features such as width and height can be passed to it. • window.close(): closes the current browser window (normally, a window can only be closed by the script that opened it). • window.moveTo(x, y): moves the window to the specified absolute position, given by the x and y coordinates, on the screen. • window.resizeTo(width, height): resizes the window to the specified width and height, measured in pixels.
-
Enlist some drawbacks of JavaScript.
Topic: JavaScript Basics
• Security: JavaScript code runs on the user's computer and its source can be viewed by anyone, so it can be misused and cannot be trusted for sensitive work. • Browser dependence: JavaScript is interpreted by the browser, and different browsers may interpret the same code differently. • It can be disabled: if the user disables JavaScript in the browser, all its functionality stops working. • No file access: JavaScript cannot read or write files on the user's computer. • No multithreading: JavaScript is single-threaded and does not support multiprocessing. • Rendering problems: a JavaScript error can stop the whole web page from rendering properly.