viii. Which of the following jQuery method is used to attach a handler to an event? (1 Mark)
A. unbind () method
B. attach () method
C. bind () method
D. None of the above
Answer (Click to show)
C. bind () method
ix. $(this) in jQuery is used when: (1 Mark)
A. an HTML element references the entire document
B. an HTML element references its own action
C. an HTML element references the action of its parent element
D. All of the above
Answer (Click to show)
B. an HTML element references its own action
x. Which type of JavaScript language is: (1 Mark)
A. Object-Oriented
B. Object-Based
C. Assembly-language
D. High-level
Answer (Click to show)
B. Object-Based
Question Two: Fill in the Blanks
a. ______ tag contain information about the author, copyright information, etc. (1 Mark)
Answer (Click to show)
<footer>
b. ______ tag can be used to mark up a conversation. (1 Mark)
Answer (Click to show)
<dialog>
c. ______ represents a measurement, such as disk usage. (1 Mark)
Answer (Click to show)
<meter>
d. ______ improve the performance of our websites by avoiding the need to download images off the network. (1 Mark)
Answer (Click to show)
<canvas>
e. ______ element represents a run of text in one document marked or highlighted for reference purposes. (1 Mark)
Answer (Click to show)
<mark>
f. ______ tag represents a section of the document intended for navigation. (1 Mark)
Answer (Click to show)
<nav>
g. ______ tag represents a piece of content that is only slightly related to the rest of the page. (1 Mark)
Answer (Click to show)
<aside>
h. ______ tag represents an independent piece of content of a document, such as a blog entry or newspaper. (1 Mark)
Answer (Click to show)
<article>
i. ______ tag represents a generic document or application. It can be used together with h1-h6 to indicate the document structure. (1 Mark)
Answer (Click to show)
<section>
j. ______ tag can be used to associate a caption together with some embedded content, such as a graphic or video. (1 Mark)
Answer (Click to show)
<figure>
Question Three: True or False
a. JavaScript is a compiled language (1 Mark)
Answer (Click to show)
False
b. With an external style sheet, you can change the look of an entire website by changing just one file. (1 Mark)
Answer (Click to show)
True
c. jQuery can be used to create AJAX applications. (1 Mark)
Answer (Click to show)
True
d. Using the Javascript const keyword to declare a variable ensures that it will not be reassigned within its scope. (1 Mark)
Answer (Click to show)
True
e. HTML is used to create the structure of a web page. (1 Mark)
Answer (Click to show)
True
f. jQuery is a replacement for JavaScript. (1 Mark)
Answer (Click to show)
False
g. Some browsers do not support images. In this case, the alt attribute can be used to create text that appears instead of the image. (1 Mark)
Answer (Click to show)
True
h. When a Web browser displays a table, it often adds extra space. To eliminate this space use the width attribute in the <table> and <td> tags. (1 Mark)
Answer (Click to show)
False
i. A font family is a set of fonts that have similar characteristics. (1 Mark)
Answer (Click to show)
True
j. jQuery Method Chaining allows us to run multiple jQuery methods (on the same element) within a single statement. (1 Mark)
Answer (Click to show)
True
Question Four: CSS Rules
i. Make all text in the body of the document double the normal size and color the text red. (2 Marks)
Answer (Click to show)
body { font-size: 2em; color: red;}
ii. Place a background image halfway down the page, tiling it horizontally. The image should remain in place as the user scrolls up or down. (2 Marks)
iii. All h1 and h2 elements in the web page should have the following styles applied: a padding of 0.5 ems, a dashed border style, and a margin of 0.5 ems. (2 Marks)
v. Write a layout template that contains a header and two columns. Use division tags for each layout component, and use float to line up the columns side by side. Give each component a border and or a background color so you can see in which division tag you are. (2 Marks)
Assume you are a front-end developer and you are tasked to create a web application that stores information about pregnant mothers. The application needed to capture the following details about each pregnant mother: first name, middle name, surname, email address, and phone number. During the development process, the client added a requirement to also capture information about the pregnancy. Specifically, the application needed to determine whether the pregnancy was a twin or not. If the pregnancy was not a twin, the application should capture the gender and weight of the child. If the pregnancy was a twin, the application should capture the number of children (ie, the number of twins could be 2, 3, etc.). For a twin pregnancy, the application should capture the weight and gender of each child. So the number of input fields for gender and weight would depend on the number of twins. For example, if the number of twins is two, then the application should have two input fields each for the gender and weight of the two children.
You were asked to use HTML, CSS, and jQuery to create the form to capture all this information. You also needed to use JavaScript to validate the form, ensuring that no required field is left empty and that the data entered is valid. All fields should be mandatory except the middle name.
(20 Marks)
$(document).ready(function() { // Toggle pregnancy form sections based on twin selection $('#twin-pregnancy').on('change', function() { let isTwin = $(this).val() == 'yes'; $('#single-pregnancy').toggle(!isTwin); $('#twin-pregnancy-details').toggle(isTwin); }); // Generate twin fields $('#number-of-twins').on('input', function() { let numberOfTwins = $(this).val(); let twinsFields = ''; for (let i = 1; i <= numberOfTwins; i++) { twinsFields += ` <label>Child ${i} Gender:</label> <select required> <option value="">Select Gender</option> <option value="male">Male</option> <option value="female">Female</option> </select> <label>Child ${i} Weight (kg):</label> <input type="number" step="0.01" min="0" required> `; } $('#twins-info').html(twinsFields); }); // Form validation $('#pregnancy-form').on('submit', function(e) { if (!this.checkValidity()) { alert('Please fill out all required fields.'); e.preventDefault(); } });});
Question Six: To-Do List Application
Imagine you are building a web application that allows users to create and manage their personal to-do lists. When a user click āAddā button, a function named āaddTodoltemā should be called to allow user to add a new to-do item by entering a task description in an input field. When the user adds a new to-do item, it should be displayed in a table with id=ālist-itemsā. Each to-do item in the list should have a checkbox to mark it as completed, and a āDeleteā button. When the user clicks the checkbox for a to-do item, a function named ācompleteTaskā should to called to visually indicated the task as completed (by adding a strikethrough to the text). When the user clicks the āDeleteā button for a to-do item, the application should call a function ādeleteltemā which confirm the deletion with the user before removing the item the from the list. Use DOM and BOM manipulations to implement the above functionalities. (20 Marks)
Mr. Siphael is selling his car online. He has taken several photos of the carās exterior and interior, and he wants to display them on a webpage so potential buyers can view the car. He would like the webpage to have a large main image area that displays the selected photo, and a set of thumbnail images that the user can click to update the main image. Write the necessary code in a file called ācar.jsā that uses jQuery to implement the following functionality: ⢠When the user clicks on a thumbnail image of the carās exterior, the large exterior shot should be displayed in the main image area (the image with the ID ācarā). ⢠When the user clicks on a thumbnail image of the carās interior, the large interior shot should be displayed in the main image area.