Internet Programming and Applications - Exam

UNIVERSITY OF DODOMA

ACADEMIC YEAR 2021/2022


SECTION A: (15 MARKS)

Question One: Multiple Choice

i. Which tag is used to identify the keywords describing the site?
(1 Mark)

  • A. Comment tag
  • B. Title tag
  • C. Meta tag
  • D. Anchor tag

ii. Which property of a page element (eg a div) is used by JavaScript to alter the content of a page after it has loaded?
(1 Mark)

  • A. value
  • B. text
  • C. firstChild
  • D. innerHTML

iii. Which is the correct way to link to an external stylesheet from a web page?
(1 Mark)

  • A. <link rel = "stylesheet" type = "text/css" src = "styles.css" />
  • B. <link rel = "stylesheet" type = "text/css" href = "styles.css" />
  • C. <style href = "styles.css" type = "text/css" />
  • D. <style div{color: blue;} </style>

iv. Which JavaScript function is used to open a small window for user input?
(1 Mark)

  • A. alert()
  • B. prompt()
  • C. document.write()
  • D. init()

v. Which sign does jQuery use as a shortcut for jQuery?
(1 Mark)

  • A. the % sign
  • B. the ? Sign
  • C. the $ sign
  • D. the #sign

vi. $(document).ready(function() { // Some code. }); The above code is used to:
(1 Mark)

  • A. Make sure no code is executed till the entire page is fully loaded
  • B. Make sure no code is executed till the DOM is fully loaded
  • C. Make sure no browser will open till the DOM is fully loaded.
  • D. Both A and B

vii. Which property in JavaScript would you use to redirect visitor to another page?
(1 Mark)

  • A. window.location.href
  • B. document.href
  • C. java.redirect.url
  • D. link.redirect.href

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

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

x. Which type of JavaScript language is?
(1 Mark)

  • A. Object-Oriented
  • B. Object-Based
  • C. Assembly-language
  • D. High-level

Question Two: Fill in the Blanks

a. ______ tag contain information about the author, copyright information, etc.
(1 Mark)

b. ______ tag can be used to mark up a conversation.
(1 Mark)

c.______ represents a measurement, such as disk usage.
(1 Mark)

d. ______ improve the performance of our websites by avoiding the need to download images off the network.
(1 Mark)

e. ______ element represents a run of text in one document marked or highlighted for reference purposes.
(1 Mark)

f. ______ tag represents a section of the document intended for navigation.
(1 Mark)

g. ______ tag represents a piece of content that is only slightly related to the rest of the page.
(1 Mark)

h. ______ tag represents an independent piece of content of a document, such as a blog entry or newspaper.
(1 Mark)

i. ______ tag represents a generic document or application. It can be used together with h1-h6 to indicate the document structure.
(1 Mark)

j. ______ tag can be used to associate a caption together with some embedded content, such as a graphic or video.
(1 Mark)


Question Three: True or False

a. JavaScript is a compiled language
(1 Mark)

b. With an external style sheet, you can change the look of an entire website by changing just one file.
(1 Mark)

c. jQuery can be used to create AJAX applications.
(1 Mark)

d. Using the Javascript const keyword to declare a variable ensures that it will not be reassigned within its scope.
(1 Mark)

e. HTML is used to create the structure of a web page.
(1 Mark)

f. jQuery is a replacement for JavaScript.
(1 Mark)

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)

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)

i. A fontfamily is a set of fonts that have similar characteristics
(1 Mark)

j. jQuery Method Chaining allows us to run multiple jQuery methods (on the same element) within a single statement.
(1 Mark)


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)

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)

iv. Change the color of all elements with the “green-move” class to green, and shift them down 25 pixels and to the right 15 pixels.
(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)


SECTION B: (60 MARKS)

Question Five: Pregnant Mothers Web Application

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 (i.e., 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)


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 “addToDoItem” 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 “deleteItem” 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.

Assume that the thumbnail images have file names that include the ‘thumb’ substring, and the corresponding large images have the same file names but with the ‘thumb’ substring replaced by ‘large’. (20 Marks)


Question Eight: jQuery Conversions and Operations

a. Document Object Model (DOM) manipulation is so common with JavaScript, and because the JavaScript to do so can get quite lengthy, people wanted alternatives. One of the alternative is to use jQuery library. Change the following DOM statements to jQuery statements. (4 Marks Each)

i. document.getElementById('colorDiv').style.backgroundColor = 'green'
(4 Marks)

ii. document.getElementById("myImage").src = "landscape.jpg";
(4 Marks)


b. You have a CSS file called “myCss.css” as seen in the code snippet below, that defines the styles for various CSS classes, including a class named “large”. You also have an HTML element with the class “center” as seen in the code snippet below. Your task is to write a jQuery statement(s) that will change the style of the element with the class “center” to match the style of the “large” class as defined in the “myCss.css” file.

(4 Marks)

myHtml.html
    <!DOCTYPE html>
    <html>
    <head>
    <script src="myjQuery.js"></script>
    <meta charset="utf-8">
    <meta name="viewport"content="width=device-width">
    <title>Change a CSS class name using jQuery.</title>
    </head>
    <body>
    <p id ="pid" class="center"> jQuery
    Exercise</p>
    <input id="button1" type="button" value="Click to change the Class" />
    </body>
    </html>

myCss.css
p.center {
    text-align: center;
    color: red;
}
p.large {
    font-size: 200%;
}

c. Consider the code segment below, write a jQuery statement(s) that will change the url property of element with class=“link” from http://example.com to http://cp221.com (4 Marks)

    <!DOCTYPE html>
    <html>
    <head>
    <script src="myjQuery.js"></script>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width">
    <title>JS Bin</title>
    </head>
    <body>
    <a class="link"
    href="http://example.com">Visit
    wiresources/ap
    <p><input id="button1" type="button"
    value="Click to see the actual url"/></p>
    </body>
    </html>

d. Consider the code segment below. Write a jQuery statement(s) to get the value of the textbox with property “type=text”. (4 Marks)

<!DOCTYPE html>
<html>
<head>
<script src="myjQuery.js"></script>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>How to get the value of a textbox using jQuery</title>
</head>
<body>
<input type="text" value="Input text here"/>
</body>
</html>

END OF EXAMINATION PAPER