Skip to main content

Chapter 7

Web Programming I (old course)

TU BIM past exam questions

Past questions and answers

126 questions set from this chapter, 2 of them more than once. Most repeated first.

  • Asked 2 times
  • 2014 AD · 1 mark
  • 2016 AD · 1 mark

How is array created in JavaScript?

Answer

An array is created with an array literal or the Array constructor:

var fruits = ["apple", "banana", "mango"];   // literal
var nums = new Array(10, 20, 30);            // constructor

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • Asked 2 times
  • 2016 AD · 1 mark
  • 2018 AD · 1 mark

Differentiate between margin and padding.

Answer

MarginPadding
Space outside the border, between the element and other elementsSpace inside the border, between the content and the border
Always transparentTakes the background colour of the element
Can be negativeCannot be negative
Adjacent vertical margins may collapsePadding never collapses
margin: 10px;padding: 10px;

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2014 AD Model · 1 mark

What are the uses of <hn> tags? [n is number from 1 to 6]

Answer

The <h1> to <h6> tags define HTML headings. <h1> is the most important (largest) heading and <h6> the least important (smallest). They give structure to a page, help search engines and screen readers understand the content hierarchy, and are used for titles and sub-titles. Example: <h1>Main Title</h1>.

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2014 AD Model · 1 mark

Which tags are used to create ordered list?

Answer

The <ol> tag creates an ordered (numbered) list, and each item inside it is written with the <li> tag.

<ol>
  <li>First</li>
  <li>Second</li>
</ol>

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2014 AD Model · 1 mark

Write syntax of do..while loop.

Answer

do {
    // statements to be executed
} while (condition);

The body executes at least once, and then repeats as long as the condition is true. Example:

var i = 1;
do {
    document.write(i + " ");
    i++;
} while (i <= 5);

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2014 AD Model · 1 mark

What do you mean by liquid design?

Answer

Liquid (fluid) design is a layout approach in which page widths are set in relative units such as percentages or em instead of fixed pixels. The page stretches and shrinks to fill the browser window, so it adapts to different screen sizes and resolutions.

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2014 AD Model · 1 mark

What are relative URLs?

Answer

A relative URL gives the location of a resource with respect to the current page, without the protocol and domain name. For example, images/logo.png or ../css/style.css. It keeps working if the whole site is moved to another domain.

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2014 AD Model · 1 mark

How can you see the source code of a web page in web browser?

Answer

Right-click the page and choose View Page Source, or press Ctrl+U. Developer tools (F12) also show the HTML source of the page in the Elements tab.

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2014 AD Model · 1 mark

How can you know size of array in JavaScript?

Answer

Use the length property of the array:

var arr = [10, 20, 30];
console.log(arr.length); // 3

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2014 AD Model · 1 mark

What is use of 'alt' attribute used in <img> tag?

Answer

The alt attribute of <img> gives alternative text that is shown if the image cannot be loaded. It is also read by screen readers for visually impaired users and helps search engines understand the image.

<img src="photo.jpg" alt="Students in classroom">

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2014 AD Model · 1 mark

What is the purpose of using absolute positioning for an HTML element?

Answer

position: absolute removes an element from the normal document flow and places it at an exact location using top, left, right or bottom, relative to its nearest positioned ancestor (or the page if none). It is used to put elements precisely, overlay one element on another, or create menus and pop-ups.

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2014 AD Model · 1 mark

How is date object created in JavaScript?

Answer

A Date object is created with the new Date() constructor:

var d1 = new Date();                     // current date and time
var d2 = new Date(2014, 5, 15);          // year, month (0-11), day
var d3 = new Date("06/15/2014");         // from a date string
var d4 = new Date(1400000000000);        // milliseconds since 1 Jan 1970

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2014 AD Model · 4 marks

Make web page with two rows and two columns using DIV tags with the following styles: width of left column 150px; width of right column 950px; background color of right column: white; font color: gray; CSS properties: font family verdana, font size 10pt; height of top row 100px; width of top row 1200px; background color of top row: green-yellow.

Answer

<!DOCTYPE html>
<html>
<head>
<title>Div Layout</title>
<style>
  body { margin: 0; font-family: verdana; font-size: 10pt; }
  #top {
    width: 1200px;
    height: 100px;
    background-color: greenyellow;
  }
  #left {
    float: left;
    width: 150px;
  }
  #right {
    float: left;
    width: 950px;
    background-color: white;
    color: gray;
    font-family: verdana;
    font-size: 10pt;
  }
</style>
</head>
<body>
  <div id="top">Top row</div>
  <div id="left">Left column</div>
  <div id="right">Right column</div>
</body>
</html>

The top row spans the full 1200px width. The second row has two columns floated side by side: 150px + 950px = 1100px, which fits inside the 1200px page width. The right column has a white background, gray text, Verdana font and 10pt size, as required.

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2014 AD Model · 4 marks

Make a web form with the following fields: Name (text box); Gender (Female / Male options); Country (drop-down "Choose an item."); Hobbies (check boxes: Reading, Writing, Running); and a Submit button.

Answer

<form action="#" method="post">
  <p>
    <label for="name">Name:</label>
    <input type="text" id="name" name="name">
  </p>
  <p>
    Gender:
    <input type="radio" id="f" name="gender" value="Female">
    <label for="f">Female</label>
    <input type="radio" id="m" name="gender" value="Male">
    <label for="m">Male</label>
  </p>
  <p>
    <label for="country">Country:</label>
    <select id="country" name="country">
      <option value="">Choose an item.</option>
      <option value="Nepal">Nepal</option>
      <option value="India">India</option>
      <option value="China">China</option>
    </select>
  </p>
  <p>
    Hobbies:
    <input type="checkbox" name="hobby" value="Reading"> Reading
    <input type="checkbox" name="hobby" value="Writing"> Writing
    <input type="checkbox" name="hobby" value="Running"> Running
  </p>
  <p><input type="submit" value="Submit"></p>
</form>

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2014 AD Model · 4 marks

Write a JavaScript program that adds two Date objects given in 'mm/dd/yyyy/' format and displays oldest date according to year only.

Answer

The program reads two dates in mm/dd/yyyy format, adds them (as millisecond values, giving the combined date value) and reports which date is older by year only.

<script>
function parseDate(s) {
  var p = s.split("/");
  return new Date(parseInt(p[2]), parseInt(p[0]) - 1, parseInt(p[1]));
}

var d1 = parseDate(prompt("Enter first date (mm/dd/yyyy)"));
var d2 = parseDate(prompt("Enter second date (mm/dd/yyyy)"));

// adding the two Date objects (milliseconds since 1970)
var sum = d1.getTime() + d2.getTime();
document.write("Sum of the dates (ms): " + sum + "<br>");

var y1 = d1.getFullYear();
var y2 = d2.getFullYear();

if (y1 < y2) {
  document.write("Oldest date is the first: " + d1.toDateString());
} else if (y2 < y1) {
  document.write("Oldest date is the second: " + d2.toDateString());
} else {
  document.write("Both dates are in the same year " + y1);
}
</script>

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2014 AD Model · 4 marks

Write function in JavaScript which takes a reference of a division (<div>) of a web page and changes text and formatting (font color, font family, font size, background color) of that division.

Answer

<div id="box">Original text</div>
<button onclick="changeDiv(document.getElementById('box'))">Change</button>

<script>
function changeDiv(div) {
  div.innerHTML = "This text has been changed";
  div.style.color = "white";
  div.style.fontFamily = "Verdana";
  div.style.fontSize = "18px";
  div.style.backgroundColor = "blue";
}
</script>

The function receives a reference to the <div> element, replaces its text through innerHTML, and sets font colour, font family, font size and background colour through the style object.

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2014 AD Model · 4 marks

Make a web form for taking one string and one number. If given string is 'javascript' and number is 198877 display welcome message otherwise ask user to re-enter string and number.

Answer

<!DOCTYPE html>
<html>
<head>
<title>Login Check</title>
<script>
function check() {
  var s = document.getElementById("str").value;
  var n = document.getElementById("num").value;
  if (s === "javascript" && Number(n) === 198877) {
    alert("Welcome!");
    return true;
  } else {
    alert("Wrong string or number. Please re-enter.");
    document.getElementById("str").value = "";
    document.getElementById("num").value = "";
    document.getElementById("str").focus();
    return false;
  }
}
</script>
</head>
<body>
<form onsubmit="return check()">
  String: <input type="text" id="str"><br><br>
  Number: <input type="number" id="num"><br><br>
  <input type="submit" value="Submit">
</form>
</body>
</html>

On submit, check() compares the values. If both match, a welcome message is shown; otherwise an alert asks the user to re-enter and the fields are cleared.

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2014 AD Model · 5 marks

Explain how external and internal CSS are used with an example.

Answer

Internal CSS is written inside a <style> element in the <head> of the same HTML page. It affects only that page.

<head>
  <style>
    p { color: blue; font-size: 14px; }
  </style>
</head>

External CSS is written in a separate .css file and linked to the page using the <link> tag in the <head>. One file can style many pages, so a whole site can be changed by editing a single file.

style.css:

p { color: blue; font-size: 14px; }
h1 { color: green; }

index.html:

<head>
  <link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
  <h1>Heading</h1>
  <p>This paragraph is styled.</p>
</body>

Difference: internal CSS suits a single page and needs no extra file, while external CSS gives reuse, easier maintenance, and faster loading of later pages because the browser caches the stylesheet. (Inline CSS, using the style attribute, has the highest priority, then internal and external styles follow the order in which they appear.)

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2014 AD Model · 5 marks

What do you mean by form validation? Explain with simple example.

Answer

Form validation is the process of checking the data entered by a user in a form to make sure it is complete and in the correct format before it is sent to the server. It can be done on the client side with JavaScript (fast feedback, less server load) and must also be repeated on the server side for security.

Common checks are: required fields are not empty, email format is correct, a number lies in a range, password length is sufficient.

Example:

<form name="f" onsubmit="return validate()">
  Name: <input type="text" name="uname"><br>
  Email: <input type="text" name="email"><br>
  <input type="submit" value="Submit">
</form>

<script>
function validate() {
  var name = document.f.uname.value;
  var email = document.f.email.value;
  if (name == "") {
    alert("Name must be filled out");
    return false;
  }
  if (email.indexOf("@") == -1 || email.indexOf(".") == -1) {
    alert("Enter a valid email address");
    return false;
  }
  return true;
}
</script>

If validate() returns false, the form is not submitted and the user must correct the input.

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2014 AD · 1 mark

What is WWW?

Answer

The World Wide Web (WWW) is a system of interlinked hypertext documents and resources (web pages, images, videos) stored on web servers worldwide and accessed over the Internet through a browser using HTTP and URLs.

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2014 AD · 1 mark

What are jobs of web server?

Answer

A web server accepts HTTP requests from clients (browsers), locates the requested resource (static file or dynamically generated page), processes scripts when needed, and sends back an HTTP response. It also handles logging, security/authentication, and multiple simultaneous clients.

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2014 AD · 1 mark

What is $_POST in PHP?

Answer

$_POST is a PHP superglobal associative array that holds the data submitted to the script by an HTML form using method="post". Values are read by field name, e.g. $_POST['username']. The data is sent in the request body, not shown in the URL.

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2014 AD · 1 mark

What is use of <img> tag?

Answer

The <img> tag embeds an image in a web page. It is an empty tag; the src attribute gives the image file and alt the alternative text, e.g. <img src="logo.png" alt="Logo" width="100">.

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2014 AD · 1 mark

Define DOM.

Answer

The Document Object Model (DOM) is a platform- and language-independent programming interface that represents an HTML/XML document as a tree of objects (nodes), so scripts such as JavaScript can access and change its content, structure and style.

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2014 AD · 1 mark

What is middle tier in 3-tier architecture?

Answer

The middle tier (application tier) sits between the client (presentation tier) and the database (data tier). It contains the business logic: it receives requests from the client, processes them, communicates with the database, and returns results to the client. Web servers and application servers (e.g. PHP scripts) belong to this tier.

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2014 AD · 1 mark

What is use of 'href' property?

Answer

The href attribute specifies the destination URL of a link. In the anchor tag it makes the text or image clickable, e.g. <a href="https://example.com">Visit</a>. It is also used in <link href="style.css"> to refer to external style sheets.

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2014 AD · 1 mark

Which function is used in JavaScript to display message in box?

Answer

The alert() function displays a message in a dialog box, e.g. alert("Hello");. (confirm() and prompt() show similar boxes with OK/Cancel and an input field.)

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2014 AD · 1 mark

What are the benefits of data backups?

Answer

Data backups allow recovery of data after hardware failure, accidental deletion, virus attacks, theft or disasters. They protect against data loss, ensure business continuity, allow restoration of earlier versions, and reduce downtime and cost of recovery.

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2014 AD · 3 marks

Explain different types of lists with appropriate examples.

Answer

HTML provides three types of lists.

1. Unordered list (<ul>): items are marked with bullets; each item is in <li>.

<ul>
  <li>Rice</li>
  <li>Dal</li>
</ul>

2. Ordered list (<ol>): items are numbered (or lettered with the type attribute).

<ol type="1">
  <li>Wake up</li>
  <li>Study</li>
</ol>

3. Description (definition) list (<dl>): a list of terms <dt> with their descriptions <dd>.

<dl>
  <dt>HTML</dt>
  <dd>Language for web pages</dd>
</dl>

Lists can be nested by placing a list inside an <li> item.

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2014 AD · 3 marks

What is use of switch...case in JavaScript? Write an example.

Answer

The switch...case statement selects one of many blocks of code to execute by comparing an expression with several case values. It is cleaner than a long if...else if chain. break stops execution from falling through to the next case, and default runs when no case matches.

var day = 3;
var name;
switch (day) {
  case 1:
    name = "Sunday";
    break;
  case 2:
    name = "Monday";
    break;
  case 3:
    name = "Tuesday";
    break;
  default:
    name = "Another day";
}
document.write(name);   // Tuesday

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2014 AD · 3 marks

How client side scripting language differs from server side scripting language? Explain.

Answer

Client-side scriptingServer-side scripting
Runs in the user's browserRuns on the web server
Examples: JavaScript, VBScriptExamples: PHP, ASP.NET, JSP, Node.js
Code is visible to the user (view source)Code is hidden; only the output (HTML) is sent
Used for validation, animation, dynamic UIUsed for database access, authentication, processing forms
Cannot directly access server resources or the databaseCan access files and databases on the server
Reduces server load and gives fast responseLoads the server; needs a request/response round trip
Depends on the browser's supportIndependent of the browser

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2014 AD · 3 marks

Briefly explain different types of CSS with appropriate examples.

Answer

CSS can be applied to HTML in three ways.

1. Inline CSS: written in the style attribute of a single element; affects only that element.

<p style="color:red; font-size:16px;">Hello</p>

2. Internal (embedded) CSS: written in a <style> element in the <head> of the page; affects that page only.

<head>
  <style>
    h1 { color: blue; }
    p  { text-align: justify; }
  </style>
</head>

3. External CSS: written in a separate .css file and linked with <link>; one file can style many pages, which makes it the most maintainable.

<link rel="stylesheet" href="style.css">

When rules conflict, inline overrides internal, which overrides external (the last-defined rule wins at equal specificity).

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2014 AD · 3 marks

Write HTML code to create the following table: (a table with columns "Roll Number", "Name" and a merged heading "Contract Detail" spanning the sub-columns "Email" and "Phone Number")

Answer

The merged heading is made with colspan; the first two columns span both header rows with rowspan.

<table border="1" cellpadding="5">
  <tr>
    <th rowspan="2">Roll Number</th>
    <th rowspan="2">Name</th>
    <th colspan="2">Contract Detail</th>
  </tr>
  <tr>
    <th>Email</th>
    <th>Phone Number</th>
  </tr>
  <tr>
    <td>1</td>
    <td>Ram Sharma</td>
    <td>ram@example.com</td>
    <td>9841000000</td>
  </tr>
</table>

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2014 AD · 5 marks

Write JavaScript code to ensure that the following user submitted data are in correct format: roll_number, name, email and phone_number. [Hint: roll_number and phone_number are numbers, name is not blank and email is in a valid format.]

Answer

<form name="f" onsubmit="return validate()">
  Roll Number: <input type="text" name="roll_number"><br>
  Name: <input type="text" name="name"><br>
  Email: <input type="text" name="email"><br>
  Phone Number: <input type="text" name="phone_number"><br>
  <input type="submit" value="Submit">
</form>

<script>
function validate() {
  var f = document.forms["f"];
  var roll = f.roll_number.value.trim();
  var name = f.name.value.trim();
  var email = f.email.value.trim();
  var phone = f.phone_number.value.trim();

  if (roll === "" || isNaN(roll)) {
    alert("Roll number must be a number.");
    f.roll_number.focus();
    return false;
  }
  if (name === "") {
    alert("Name must not be blank.");
    f.name.focus();
    return false;
  }
  var emailPattern = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
  if (!emailPattern.test(email)) {
    alert("Enter a valid email address.");
    f.email.focus();
    return false;
  }
  if (phone === "" || isNaN(phone)) {
    alert("Phone number must be a number.");
    f.phone_number.focus();
    return false;
  }
  return true;
}
</script>

The function runs on onsubmit; returning false stops the form from being sent, so only correctly formatted data reaches the server.

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2014 AD · 5 marks

Write PHP code to capture user submitted data (name, age, address) and insert them into a database table. Make your assumptions about name and type of all the variables and database.

Answer

Assumptions: database school, table person(id INT AUTO_INCREMENT PRIMARY KEY, name VARCHAR(50), age INT, address VARCHAR(100)), MySQL on localhost with user root and an empty password.

HTML form (form.html)

<form method="post" action="save.php">
  Name: <input type="text" name="name"><br>
  Age: <input type="text" name="age"><br>
  Address: <input type="text" name="address"><br>
  <input type="submit" value="Save">
</form>

save.php

<?php
$conn = mysqli_connect("localhost", "root", "", "school");
if (!$conn) {
    die("Connection failed: " . mysqli_connect_error());
}

$name    = $_POST['name'];
$age     = (int) $_POST['age'];
$address = $_POST['address'];

$stmt = mysqli_prepare($conn, "INSERT INTO person (name, age, address) VALUES (?, ?, ?)");
mysqli_stmt_bind_param($stmt, "sis", $name, $age, $address);

if (mysqli_stmt_execute($stmt)) {
    echo "Record inserted successfully.";
} else {
    echo "Error: " . mysqli_error($conn);
}

mysqli_stmt_close($stmt);
mysqli_close($conn);
?>

The values are read from the $_POST array, and a prepared statement is used so that user input cannot cause SQL injection.

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2014 AD · 5 marks

Write short notes on:
a. Session variable b. HTTP

Answer

(a) Session variable

A session is a way of storing information about a user across multiple pages of a web application. HTTP is stateless, so the server creates a unique session ID for each visitor and keeps the data on the server. The ID is sent to the browser, usually as a cookie, and the browser returns it with each request. Session variables hold user-specific values such as login name or shopping cart items and remain available until the session ends (logout, timeout or browser close). In PHP:

<?php
session_start();
$_SESSION["user"] = "Ram";
echo $_SESSION["user"];
?>

session_destroy() removes the session data. Sessions are more secure than cookies because the data stays on the server.

(b) HTTP

HyperText Transfer Protocol is the application-layer protocol used for communication between web clients (browsers) and web servers. It follows a request-response model: the client sends a request (method such as GET or POST, URL, headers, optional body) and the server returns a response (status code such as 200 or 404, headers, and the content). It normally runs over TCP on port 80 (HTTPS uses port 443 with encryption). HTTP is stateless, so each request is independent; cookies and sessions are used to maintain state.

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2015 AD · 1 mark

Why is <head> tag used in HTML file?

Answer

The <head> tag holds information about the document that is not displayed on the page itself, such as the <title>, <meta> tags, links to CSS (<link>), <style> and <script> elements.

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2015 AD · 1 mark

List HTML elements that are used to add quotations or citations in web page.

Answer

  • <blockquote> for a long block quotation
  • <q> for a short inline quotation
  • <cite> for the title of a cited work

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2015 AD · 1 mark

What is the use of <span> elements?

Answer

<span> is a generic inline element with no meaning of its own. It is used to group a part of text or other inline content so that it can be styled with CSS or manipulated with JavaScript, for example <span style="color:red">important</span>.

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2015 AD · 1 mark

What is the use of <img> tag?

Answer

The <img> tag embeds an image in a web page. It is an empty tag; src gives the image file and alt gives alternative text, for example <img src="photo.jpg" alt="My photo" width="200" height="150">.

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2015 AD · 1 mark

List the possible values of overflow property.

Answer

The values of the CSS overflow property are visible (default), hidden, scroll, auto and inherit.

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2015 AD · 1 mark

How can you change the color of visited link using CSS?

Answer

Use the :visited pseudo-class of the anchor element:

a:visited {
  color: purple;
}

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2015 AD · 1 mark

In JavaScript, if you have not given any value to a variable then what value that variable will hold?

Answer

It holds the special value undefined.

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2015 AD · 1 mark

What would be the output of the following JavaScript program?
html\n<script type="text/JavaScript">\nmyString = "judge";\nmyString = myString.charAt(2);\nmyString = myString.toUpperCase();\ndocument.write(myString);\n</script>\n

Answer

Output: D

"judge".charAt(2) returns the character at index 2 (j=0, u=1, d=2), which is "d". toUpperCase() converts it to "D", and document.write prints it.

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2015 AD · 1 mark

How will you create array in JavaScript?

Answer

An array can be created with an array literal or with the Array constructor:

var fruits = ["apple", "banana", "mango"];   // literal
var nums = new Array(10, 20, 30);            // constructor
var empty = new Array(5);                    // empty array of length 5

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2015 AD · 4 marks

Write HTML code to produce the following output: a table with columns "Actor" and "Movies" in which the actor "Tom Hanks" spans three rows listing the movies "Forrest camp", "Green mile" and "Philadelphia".

Answer

<table border="1" cellpadding="5">
  <tr>
    <th>Actor</th>
    <th>Movies</th>
  </tr>
  <tr>
    <td rowspan="3">Tom Hanks</td>
    <td>Forrest Gump</td>
  </tr>
  <tr>
    <td>Green Mile</td>
  </tr>
  <tr>
    <td>Philadelphia</td>
  </tr>
</table>

The cell "Tom Hanks" uses rowspan="3" so it spans the three rows; the second and third rows therefore contain only the movie cell. The movie names are written as given in the question ("Forrest camp" is presumably Forrest Gump).

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2015 AD · 4 marks

Make a HTML form that has following fields: Username, Password, Gender (Male, Female), Interests (Traveling, Singing) and Photo Upload.

Answer

<form action="register.php" method="post" enctype="multipart/form-data">
  <p>Username: <input type="text" name="username"></p>
  <p>Password: <input type="password" name="password"></p>
  <p>Gender:
    <input type="radio" name="gender" value="male"> Male
    <input type="radio" name="gender" value="female"> Female
  </p>
  <p>Interests:
    <input type="checkbox" name="interest[]" value="traveling"> Traveling
    <input type="checkbox" name="interest[]" value="singing"> Singing
  </p>
  <p>Photo: <input type="file" name="photo"></p>
  <p><input type="submit" value="Submit"> <input type="reset" value="Reset"></p>
</form>

Radio buttons share one name so only one can be chosen, checkboxes allow several, and enctype="multipart/form-data" is required for file upload.

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2015 AD · 4 marks

Write a program in JavaScript that asks two number with use and display the sum of those two numbers.

Answer

<html>
<body>
<script type="text/javascript">
  var a = parseFloat(prompt("Enter first number:"));
  var b = parseFloat(prompt("Enter second number:"));
  var sum = a + b;
  document.write("The sum of " + a + " and " + b + " is " + sum);
</script>
</body>
</html>

prompt() returns a string, so parseFloat() converts the input to numbers; otherwise + would concatenate the strings.

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2015 AD · 4 marks

Write JavaScript code to validate user submitted data - Username, Password and Phone. [Hint: None of the fields are blank, password is at least 6 characters long and phone number contains 7 digits.]

Answer

<form name="f" onsubmit="return validate()">
  Username: <input type="text" name="username"><br>
  Password: <input type="password" name="password"><br>
  Phone: <input type="text" name="phone"><br>
  <input type="submit" value="Submit">
</form>

<script>
function validate() {
  var f = document.forms["f"];
  var u = f.username.value;
  var p = f.password.value;
  var ph = f.phone.value;

  if (u === "" || p === "" || ph === "") {
    alert("No field can be blank.");
    return false;
  }
  if (p.length < 6) {
    alert("Password must be at least 6 characters long.");
    return false;
  }
  if (!/^[0-9]{7}$/.test(ph)) {
    alert("Phone number must contain exactly 7 digits.");
    return false;
  }
  return true;
}
</script>

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2015 AD · 4 marks

Write JavaScript code to create an array that holds following musical instruments - murchunga madal and sarangi. Convert that array into string and print that array.

Answer

<script type="text/javascript">
  var instruments = ["murchunga", "madal", "sarangi"];
  var str = instruments.toString();   // "murchunga,madal,sarangi"
  document.write(str);
</script>

toString() joins the elements with commas, so the output is murchunga,madal,sarangi. instruments.join(", ") could be used for a different separator.

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2015 AD · 5 marks

Why it is necessary for a website developer to know type of web browsers used by users? How some information about the web browsers can be known?

Answer

Why a developer needs to know the browsers used

  • Different browsers (Chrome, Firefox, Safari, Edge, mobile browsers) and versions render HTML, CSS and JavaScript differently, and some do not support newer features. A page that looks right in one may break in another.
  • Knowing the browsers lets the developer test the site on them, supply fallbacks or alternative code, and be sure that all users get a usable page.
  • Usage statistics also show which browsers deserve priority and whether mobile design is needed.

How browser information can be obtained

  • JavaScript navigator object: navigator.userAgent, navigator.appName, navigator.appVersion and navigator.platform give the browser name, version and operating system.
document.write(navigator.userAgent);
  • HTTP User-Agent header: the browser sends it with every request, and server-side code can read it, e.g. $_SERVER['HTTP_USER_AGENT'] in PHP.
  • Server logs and analytics tools (such as Google Analytics) summarise the browsers of visitors.
  • Feature detection (checking whether a feature exists before using it) is often better than relying on the browser name.

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2016 AD · 1 mark

Differentiate between block level and inline elements?

Answer

Block-level elementInline element
Starts on a new line and takes the full available widthDoes not start a new line; takes only the width of its content
Width and height can be setWidth and height cannot be set
Top and bottom margins applyVertical margins have no effect
May contain block and inline elementsShould contain only text or other inline elements
Examples: <div>, <p>, <h1>, <ul>Examples: <span>, <a>, <b>, <img>

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2016 AD · 1 mark

Write a CSS rule to use image as bullet point.

Answer

ul {
  list-style-image: url("bullet.png");
}

Alternatively list-style: url("bullet.png") inside; can be used.

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2016 AD · 1 mark

Write a source code to create an image button.

Answer

<input type="image" src="button.png" alt="Submit" width="100" height="40">

An <input> of type image acts as a graphical submit button. It can also be built with <button><img src="button.png" alt="Submit"></button>.

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2016 AD · 1 mark

Why absolute path should not be used while developing web pages?

Answer

An absolute path (e.g. C:\site\images\a.jpg or http://www.example.com/images/a.jpg) is tied to one fixed location. When the site is moved to another folder, computer, server or domain, every such link breaks and has to be edited. A relative path (e.g. images/a.jpg) depends only on the position of the file relative to the current page, so the whole site works wherever it is placed. A local drive path would also not exist on the visitor's computer.

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2016 AD · 1 mark

For what purpose float property used?

Answer

The CSS float property (left, right, none) moves an element to the left or right of its container so that text and inline content wrap around it. It is used to place images beside text and to build multi-column layouts. clear is used to stop wrapping after floated elements.

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2016 AD · 1 mark

What do you mean by sitemap?

Answer

A sitemap is a page or file that lists the pages of a website, usually in a hierarchical structure. An HTML sitemap helps visitors navigate the site, while an XML sitemap (sitemap.xml) lists the URLs for search engines so that they can crawl and index all pages. It also helps in planning the site structure.

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2016 AD · 1 mark

Differentiate between substring and substr functions.

Answer

Both extract part of a string, but their second parameter differs.

substring(start, end)substr(start, length)
Second parameter is the end index (not included)Second parameter is the number of characters to extract
Swaps the arguments if start is greater than endDoes not swap
Negative values are treated as 0Negative start counts from the end of the string
StandardDeprecated

Example with s = "Hello World": s.substring(1, 4) gives "ell" and s.substr(1, 4) gives "ello".

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2016 AD · 1 mark

How is text-shadow property used?

Answer

text-shadow adds a shadow to text. Syntax: text-shadow: h-shadow v-shadow blur-radius color;

h1 {
  text-shadow: 2px 2px 5px gray;
}

Here the shadow is 2px to the right, 2px down, with a 5px blur in gray. Multiple shadows can be separated by commas.

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2016 AD · 4 marks

Write a source code to display following form. (A form with fields: Trim Number, Form Prepared By, Dept / Division, Email, a "Visa Required" Yes/No radio pair, "Visitor Visa Type" drop-down ("Pleased Select"), a "Send Mail" check box, and SEND and CLEAR buttons.)

Answer

<form action="#" method="post">
  <table>
    <tr><td>Trim Number</td><td><input type="text" name="trim"></td></tr>
    <tr><td>Form Prepared By</td><td><input type="text" name="prepared_by"></td></tr>
    <tr><td>Dept / Division</td><td><input type="text" name="dept"></td></tr>
    <tr><td>Email</td><td><input type="text" name="email"></td></tr>
    <tr>
      <td>Visa Required</td>
      <td>
        <input type="radio" name="visa" value="yes"> Yes
        <input type="radio" name="visa" value="no"> No
      </td>
    </tr>
    <tr>
      <td>Visitor Visa Type</td>
      <td>
        <select name="visa_type">
          <option value="">Pleased Select</option>
          <option value="tourist">Tourist</option>
          <option value="business">Business</option>
        </select>
      </td>
    </tr>
    <tr>
      <td>Send Mail</td>
      <td><input type="checkbox" name="send_mail" value="yes"></td>
    </tr>
    <tr>
      <td></td>
      <td>
        <input type="submit" value="SEND">
        <input type="reset" value="CLEAR">
      </td>
    </tr>
  </table>
</form>

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2016 AD · 4 marks

Write a JavaScript function that checks password and retyped password of two different password fields are same or not.

Answer

<form name="f" onsubmit="return checkPassword()">
  Password: <input type="password" name="pw"><br>
  Retype Password: <input type="password" name="pw2"><br>
  <input type="submit" value="Submit">
</form>

<script>
function checkPassword() {
  var p1 = document.forms["f"].pw.value;
  var p2 = document.forms["f"].pw2.value;
  if (p1 !== p2) {
    alert("Passwords do not match.");
    return false;
  }
  alert("Passwords match.");
  return true;
}
</script>

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2016 AD · 4 marks

Write a JavaScript code to calculate difference between two dates given by user.

Answer

Date 1: <input type="date" id="d1"><br>
Date 2: <input type="date" id="d2"><br>
<button onclick="diff()">Calculate</button>
<p id="result"></p>

<script>
function diff() {
  var a = new Date(document.getElementById("d1").value);
  var b = new Date(document.getElementById("d2").value);
  if (isNaN(a) || isNaN(b)) {
    alert("Please enter both dates.");
    return;
  }
  var ms = Math.abs(b - a);                       // difference in milliseconds
  var days = Math.round(ms / (1000 * 60 * 60 * 24));
  document.getElementById("result").innerHTML =
      "Difference = " + days + " day(s)";
}
</script>

Subtracting two Date objects gives milliseconds; dividing by 1000×60×60×24=864000001000 \times 60 \times 60 \times 24 = 86400000 converts to days.

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2016 AD · 4 marks

Write a JavaScript code to check if a number given by user is prime or not.

Answer

<script type="text/javascript">
  var n = parseInt(prompt("Enter a number:"));
  var prime = true;

  if (isNaN(n) || n < 2) {
    prime = false;
  } else {
    for (var i = 2; i * i <= n; i++) {
      if (n % i === 0) {
        prime = false;
        break;
      }
    }
  }

  if (prime)
    document.write(n + " is a prime number.");
  else
    document.write(n + " is not a prime number.");
</script>

A number n≥2n \ge 2 is prime if it has no divisor from 2 up to n\sqrt{n}, so the loop runs while i2≤ni^2 \le n.

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2016 AD · 4 marks

Write a source code to generate the following layout. Height and width of each divs are 100px and 100px respectively. The background colors for the divs are specified in divs below. (A layout of coloured divs is given in a figure in the original paper.)

Answer

The figure is not reproduced here, so the layout is assumed to be a 2 x 2 grid of 100px x 100px coloured divs (red, green on the top row; blue, yellow below). The divs are floated left inside a 200px wide container.

<html>
<head>
<style>
  #container { width: 200px; }
  .box { width: 100px; height: 100px; float: left; }
  #d1 { background-color: red; }
  #d2 { background-color: green; }
  #d3 { background-color: blue; }
  #d4 { background-color: yellow; }
</style>
</head>
<body>
  <div id="container">
    <div class="box" id="d1"></div>
    <div class="box" id="d2"></div>
    <div class="box" id="d3"></div>
    <div class="box" id="d4"></div>
  </div>
</body>
</html>

For a different arrangement, change the container width or the colours, or position the divs with position:absolute; top; left.

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2016 AD · 5 marks

Differentiate between get and post methods. What is browser compatibility? How the browser compatible web page is created?

Answer

GET vs POST

GETPOST
Form data is appended to the URL as a query string (page.php?name=Ram&age=20)Data is sent in the body of the HTTP request
Visible in the address bar, history and logs, so not secureNot shown in the URL, safer for passwords
Limited length (about 2000 characters)No practical size limit
Can be bookmarked and cachedCannot be bookmarked; not cached
Only text (ASCII) dataText and binary data (file upload)
Used to retrieve dataUsed to submit or change data
PHP: $_GETPHP: $_POST

Browser compatibility

Browser compatibility is the ability of a web page to display and work correctly and consistently in different browsers (Chrome, Firefox, Safari, Edge, Opera), their versions and devices, because they support HTML, CSS and JavaScript features differently.

Creating a browser-compatible page

  • Write valid, standard HTML and CSS and include a correct <!DOCTYPE>.
  • Avoid browser-specific or deprecated tags and features; use vendor prefixes (-webkit-, -moz-) where needed.
  • Use feature detection and provide fallbacks for unsupported features; use CSS resets and tested libraries such as jQuery.
  • Use relative units and responsive design for different screen sizes.
  • Test the page in several browsers and versions and fix the differences.

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2016 AD · 5 marks

Explain the form validation with an example.

Answer

Form validation is the process of checking the data entered by the user in a form before it is processed or sent to the server. It makes sure that required fields are filled and that data is in the correct format (numbers, email, length), which reduces errors and server load and improves security. It can be done on the client side (JavaScript, HTML5 attributes), which gives immediate feedback, and on the server side (PHP etc.), which is necessary because client-side checks can be bypassed.

Example (client-side with JavaScript)

<form name="reg" onsubmit="return validate()">
  Name: <input type="text" name="name"><br>
  Email: <input type="text" name="email"><br>
  Age: <input type="text" name="age"><br>
  <input type="submit" value="Register">
</form>

<script>
function validate() {
  var f = document.forms["reg"];
  if (f.name.value.trim() === "") {
    alert("Name is required.");
    return false;
  }
  if (!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(f.email.value)) {
    alert("Enter a valid email.");
    return false;
  }
  if (isNaN(f.age.value) || f.age.value < 1) {
    alert("Age must be a positive number.");
    return false;
  }
  return true;
}
</script>

When the user presses Register, validate() runs; if it returns false the submission is cancelled and the message tells the user what to correct.

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2017 AD · 1 mark

Define tags and elements.

Answer

A tag is a keyword enclosed in angle brackets that marks the start or end of an HTML construct, such as <p> and </p>.

An element is the complete construct: start tag, content and end tag, e.g. <p>Hello</p>. Some elements are empty and have only one tag, such as <br>.

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2017 AD · 1 mark

What is the use of <PRE> tag?

Answer

The <pre> tag displays preformatted text. Spaces, tabs and line breaks in the source are kept and the text is shown in a fixed-width (monospace) font, which is useful for program code and poems.

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2017 AD · 1 mark

How is id attribute specified?

Answer

The id attribute is written inside the start tag as id="value", and the value must be unique in the page:

<p id="intro">Welcome</p>

It is used in CSS with #intro { color: blue; } and in JavaScript with document.getElementById("intro"), and as a link target with <a href="#intro">.

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2017 AD · 1 mark

What are the things that are considered while using images in a webpage?

Answer

While using images in a web page, the following should be considered:

  • File format: JPEG for photographs, PNG for graphics needing transparency, GIF for simple animation, SVG for scalable icons.
  • File size and loading time: compress and optimise images so the page loads quickly.
  • Dimensions: specify width and height (or use responsive CSS) so the layout does not jump.
  • Alt text: always give an alt attribute for accessibility and when the image fails to load.
  • Relevance, quality and copyright: use clear, relevant images that you have the right to use.

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2017 AD · 1 mark

Define padding?

Answer

Padding is the space between an element's content and its border, inside the element. It is set with the CSS padding property (or padding-top, padding-right, padding-bottom, padding-left). The element's background colour also fills the padding area.

p { padding: 10px 20px; }

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2017 AD · 1 mark

What is the use of overflow property?

Answer

The CSS overflow property controls what happens when content is larger than its container box. Its values are:

  • visible (default): content spills outside the box.
  • hidden: the extra content is clipped.
  • scroll: scrollbars are always shown.
  • auto: scrollbars appear only when needed.
div { width: 200px; height: 100px; overflow: auto; }

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2017 AD · 1 mark

Write a CSS rule to use image as bullet points in a list.

Answer

Use the list-style-image property:

ul {
  list-style-image: url("bullet.png");
}

Each <li> of the list now shows bullet.png as its bullet point.

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2017 AD · 1 mark

Differentiate between fixed width design and liquid design.

Answer

Fixed width designLiquid (fluid) design
Page width is set in absolute units such as px, e.g. width: 960px.Page width is set in relative units such as %, e.g. width: 90%.
Layout stays the same on every screen size.Layout stretches or shrinks with the browser window.
May need horizontal scrolling on small screens and leaves empty space on large ones.Adapts better to different screens, including mobiles.
Easier to control and design precisely.Harder to control; content may look stretched.

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2017 AD · 1 mark

What is the use of lastIndexOf() function?

Answer

lastIndexOf() returns the position of the last occurrence of a specified substring in a string, searching backwards from the end. It returns -1 if the text is not found. Index counting starts at 0.

var s = "Hello world, hello";
s.lastIndexOf("o");   // 16
s.lastIndexOf("xyz"); // -1

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2017 AD · 1 mark

What is the use of substring()?

Answer

substring(start, end) extracts the part of a string from index start up to, but not including, index end, and returns it as a new string. If end is omitted, it extracts to the end of the string. The original string is unchanged.

var s = "JavaScript";
s.substring(0, 4);  // "Java"
s.substring(4);     // "Script"

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2017 AD · 4 marks

Write HTML code to create the following table (Make all required assumptions). (A table with rows Subject / Biology (Practical, Theory) / Chemistry (Practical, Theory) / Physics (Practical, Theory) and columns John Doe and Miriam Luther containing grades A, A+, B, C+, A-, etc.)

Answer

The table uses rowspan for the subject names and colspan for the student-name header.

<!DOCTYPE html>
<html>
<head>
  <title>Result Table</title>
  <style>
    table { border-collapse: collapse; }
    th, td { border: 1px solid black; padding: 6px 12px; text-align: center; }
  </style>
</head>
<body>
  <table>
    <tr>
      <th colspan="2" rowspan="2">Subject</th>
      <th>John Doe</th>
      <th>Miriam Luther</th>
    </tr>
    <tr>
      <th>Grade</th>
      <th>Grade</th>
    </tr>
    <tr>
      <td rowspan="2">Biology</td>
      <td>Practical</td>
      <td>A</td>
      <td>A+</td>
    </tr>
    <tr>
      <td>Theory</td>
      <td>B</td>
      <td>C+</td>
    </tr>
    <tr>
      <td rowspan="2">Chemistry</td>
      <td>Practical</td>
      <td>A-</td>
      <td>A</td>
    </tr>
    <tr>
      <td>Theory</td>
      <td>B</td>
      <td>B+</td>
    </tr>
    <tr>
      <td rowspan="2">Physics</td>
      <td>Practical</td>
      <td>A</td>
      <td>A-</td>
    </tr>
    <tr>
      <td>Theory</td>
      <td>C+</td>
      <td>B</td>
    </tr>
  </table>
</body>
</html>

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2017 AD · 4 marks

Write HTML and CSS code to generate the following layout. (use divs) (A layout of boxes is given in a figure in the original paper.)

Answer

Since the figure is not reproduced, a typical layout of boxes is assumed: a header, a left sidebar and main content side by side, and a footer.

<!DOCTYPE html>
<html>
<head>
  <title>Div Layout</title>
  <style>
    #container { width: 800px; margin: 0 auto; border: 1px solid #333; }
    #header, #footer { background: #9cf; text-align: center; padding: 15px; clear: both; }
    #sidebar { float: left; width: 200px; background: #fc9; min-height: 250px; }
    #content { float: left; width: 600px; background: #cfc; min-height: 250px; }
  </style>
</head>
<body>
  <div id="container">
    <div id="header">Header</div>
    <div id="sidebar">Sidebar</div>
    <div id="content">Main Content</div>
    <div id="footer">Footer</div>
  </div>
</body>
</html>

The sidebar and content are floated left to sit side by side (200 + 600 = 800 px), and clear: both makes the footer appear below them.

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2017 AD · 4 marks

Write a JavaScript function that takes two strings as arguments and checks them for equality. If both the strings are equal the first in uppercase else return "the two strings do not match".

Answer

function compareStrings(a, b) {
  if (a === b) {
    return a.toUpperCase();
  } else {
    return "the two strings do not match";
  }
}

document.write(compareStrings("nepal", "nepal"));  // NEPAL
document.write(compareStrings("nepal", "india"));  // the two strings do not match

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2017 AD · 4 marks

Write code to display the following form. (A form with Agent Name (three text boxes), Address, Agent Type (Individual / Organization radio buttons), Country (drop-down "Please select a country"), Email, a declaration check box "I, here by, declare that all the function provided is correct.", and Submit and Reset buttons.)

Answer

<!DOCTYPE html>
<html>
<head><title>Agent Form</title></head>
<body>
  <form action="register.php" method="post">
    <table>
      <tr>
        <td>Agent Name</td>
        <td>
          <input type="text" name="fname" placeholder="First">
          <input type="text" name="mname" placeholder="Middle">
          <input type="text" name="lname" placeholder="Last">
        </td>
      </tr>
      <tr>
        <td>Address</td>
        <td><textarea name="address" rows="3" cols="30"></textarea></td>
      </tr>
      <tr>
        <td>Agent Type</td>
        <td>
          <input type="radio" name="type" value="individual" checked> Individual
          <input type="radio" name="type" value="organization"> Organization
        </td>
      </tr>
      <tr>
        <td>Country</td>
        <td>
          <select name="country">
            <option value="">Please select a country</option>
            <option value="np">Nepal</option>
            <option value="in">India</option>
            <option value="us">USA</option>
          </select>
        </td>
      </tr>
      <tr>
        <td>Email</td>
        <td><input type="email" name="email"></td>
      </tr>
      <tr>
        <td colspan="2">
          <input type="checkbox" name="declare" value="yes">
          I, here by, declare that all the function provided is correct.
        </td>
      </tr>
      <tr>
        <td colspan="2">
          <input type="submit" value="Submit">
          <input type="reset" value="Reset">
        </td>
      </tr>
    </table>
  </form>
</body>
</html>

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2017 AD · 4 marks

Write a program in Java Script to add two prime numbers only.

Answer

The program reads two numbers, checks that both are prime, and adds them only if they are.

<!DOCTYPE html>
<html>
<head>
<title>Add Prime Numbers</title>
<script>
function isPrime(n) {
  if (n < 2) return false;
  for (var i = 2; i * i <= n; i++) {
    if (n % i === 0) return false;
  }
  return true;
}

function addPrimes() {
  var a = parseInt(document.getElementById("n1").value);
  var b = parseInt(document.getElementById("n2").value);
  var out = document.getElementById("result");
  if (isPrime(a) && isPrime(b)) {
    out.innerHTML = "Sum = " + (a + b);
  } else {
    out.innerHTML = "Both numbers must be prime.";
  }
}
</script>
</head>
<body>
  First number: <input type="text" id="n1"><br>
  Second number: <input type="text" id="n2"><br>
  <button onclick="addPrimes()">Add</button>
  <p id="result"></p>
</body>
</html>

For example, 5 and 7 give Sum = 12, while 4 and 7 give the message that both numbers must be prime.

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2017 AD · 5 marks

What do you mean by valid data? Why do we need validation? Explain with example.

Answer

Valid data is data that is correct, complete and in the format and range the application expects. For example, an email must contain @ and a domain, an age must be a number between 1 and 120, and a required field must not be empty.

Validation is the process of checking user input against such rules before it is processed or stored.

Why validation is needed:

  • It keeps wrong or incomplete data out of the database, so data stays reliable.
  • It prevents errors and crashes caused by unexpected input, such as text where a number is expected.
  • It improves security by blocking malicious input such as script or SQL injection.
  • Client-side validation gives the user instant feedback and saves server round trips.
  • It guides users to correct mistakes before submitting.

Example (JavaScript):

<form onsubmit="return validate()">
  Age: <input type="text" id="age">
  <input type="submit" value="Submit">
</form>
<script>
function validate() {
  var age = document.getElementById("age").value;
  if (age === "" || isNaN(age) || age < 1 || age > 120) {
    alert("Please enter a valid age between 1 and 120");
    return false;
  }
  return true;
}
</script>

If the user enters an empty value or "abc", the form is not submitted and an alert is shown. Client-side validation should always be repeated on the server, because it can be bypassed.

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2017 AD · 5 marks

Write notes on types of selector (id, type, class) and Internal CSS.

Answer

A CSS selector chooses the HTML elements to which a style rule applies.

Type selector: selects all elements of a given tag name.

p { color: blue; }

Class selector: starts with a dot and selects every element having that class attribute. A class can be used on many elements.

.note { background: yellow; }
<p class="note">Important</p>

ID selector: starts with # and selects the single element with that id. An id must be unique in a page.

#header { text-align: center; }
<div id="header">Welcome</div>

Internal CSS: CSS written inside a <style> element in the <head> of the HTML document. It applies only to that page.

<head>
  <style>
    body { background: #eee; }
    h1 { color: green; }
    .note { font-style: italic; }
  </style>
</head>

It is useful for styling a single page, but unlike external CSS it cannot be shared across pages. Priority is generally ID, then class, then type selector.

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2018 AD · 1 mark

Differentiate between HTML and XHTML documents.

Answer

HTMLXHTML
Based on SGML; lenient syntax.Based on XML; strict, well-formed syntax.
Tags and attributes may be upper or lower case.All tags and attributes must be in lower case.
End tags may be omitted (e.g. <p>, <li>).All elements must be closed (e.g. <br />).
Attribute values may be unquoted; minimised attributes allowed.Attribute values must be quoted; checked="checked".
Elements need not be properly nested in practice.Elements must be properly nested; one root <html> element.

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2018 AD · 1 mark

What is the use of <pre> tag?

Answer

The <pre> tag displays preformatted text. It keeps the spaces, tabs and line breaks exactly as typed in the source and usually shows the text in a monospace font. It is commonly used for program code and poems.

<pre>
Line one
    Line two (indented)
</pre>

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2018 AD · 1 mark

Differentiate between <div> and <span> elements.

Answer

<div><span>
Block-level element.Inline element.
Starts on a new line and takes the full available width.Stays in the flow of text and takes only the width of its content.
Used to group large sections and build page layouts.Used to style a small part of text within a line.
Can contain other block and inline elements.Should contain only inline content.

Example: <div>Section</div> and This is <span style="color:red">red</span> text.

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2018 AD · 1 mark

Write a source code to place an image in XHTML document.

Answer

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
  <title>Image in XHTML</title>
</head>
<body>
  <p><img src="photo.jpg" alt="A sample photo" width="200" height="150" /></p>
</body>
</html>

The <img> tag is self-closed with /> and has the required alt attribute.

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2018 AD · 1 mark

Define post method for sending the data to the server with an example.

Answer

The POST method sends form data to the server inside the body of the HTTP request, not in the URL. Because data is not visible in the address bar and has no practical size limit, it is used for passwords, large forms and file uploads. POST requests are not bookmarked or cached.

<form action="login.php" method="post">
  Username: <input type="text" name="user">
  Password: <input type="password" name="pass">
  <input type="submit" value="Login">
</form>

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2018 AD · 1 mark

What do you mean by class selector? Give an example.

Answer

A class selector selects all elements that have a particular value in their class attribute. It is written with a dot (.) followed by the class name. The same class can be applied to many elements, and one element can have several classes.

.highlight { background-color: yellow; font-weight: bold; }
<p class="highlight">This paragraph is highlighted.</p>
<span class="highlight">So is this span.</span>

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2018 AD · 1 mark

What do you mean by relative positioning? Give an example.

Answer

With position: relative, an element is positioned relative to its own normal position in the document flow. The top, right, bottom and left properties shift it from that normal place, but the space it originally occupied is preserved, so other elements do not move.

.box {
  position: relative;
  top: 20px;
  left: 30px;
}

The box appears 20px lower and 30px to the right of where it would normally be. A relatively positioned element also serves as the reference for absolutely positioned children.

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2018 AD · 1 mark

List the types of CSS.

Answer

There are three types of CSS:

  1. Inline CSS: written in the style attribute of an element.
  2. Internal (embedded) CSS: written inside a <style> element in the <head>.
  3. External CSS: written in a separate .css file and linked with <link rel="stylesheet" href="style.css">.

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2018 AD · 1 mark

Define trim function with an example.

Answer

The trim() method of a JavaScript string removes whitespace (spaces, tabs, newlines) from both the beginning and the end of the string and returns a new string. The original string is not changed and spaces inside the string remain.

var s = "   Hello World   ";
var t = s.trim();
document.write("[" + t + "]");  // [Hello World]

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 1 MCQ

Loading…

  • 2018 AD · 4 marks

Write a source code to generate the following layouts using divs. (assume all the required values) (A layout with "Header Goes Here", three columns "Topics (HTML, CSS, JavaScript)", "Main Contents Goes Here", "Other Contents...", and a footer "Copyright@ 2074 www.mysite.com".)

Answer

<!DOCTYPE html>
<html>
<head>
  <title>Div Layout</title>
  <style>
    #wrapper { width: 900px; margin: 0 auto; }
    #header { background: #6cf; text-align: center; padding: 20px; font-size: 24px; }
    #topics { float: left; width: 200px; background: #fdb; min-height: 250px; }
    #main { float: left; width: 500px; background: #dfd; min-height: 250px; text-align: center; }
    #other { float: left; width: 200px; background: #ddf; min-height: 250px; }
    #footer { clear: both; background: #6cf; text-align: center; padding: 10px; }
  </style>
</head>
<body>
  <div id="wrapper">
    <div id="header">Header Goes Here</div>
    <div id="topics">
      <h3>Topics</h3>
      <ul>
        <li>HTML</li>
        <li>CSS</li>
        <li>JavaScript</li>
      </ul>
    </div>
    <div id="main">Main Contents Goes Here</div>
    <div id="other">Other Contents...</div>
    <div id="footer">Copyright@ 2074 www.mysite.com</div>
  </div>
</body>
</html>

The three columns total 200 + 500 + 200 = 900 px, matching the wrapper, and clear: both places the footer below them.

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2018 AD · 4 marks

Write a source code to create the login form that contains a textbox for username, a textbox for password and submit button. Make the following validations (both username and password is required and cannot be the same and length should be greater than 5 characters long).

Answer

<!DOCTYPE html>
<html>
<head>
<title>Login Form</title>
<script>
function validate() {
  var u = document.getElementById("username").value;
  var p = document.getElementById("password").value;

  if (u === "" || p === "") {
    alert("Username and password are required");
    return false;
  }
  if (u === p) {
    alert("Username and password cannot be the same");
    return false;
  }
  if (u.length <= 5 || p.length <= 5) {
    alert("Username and password must be longer than 5 characters");
    return false;
  }
  return true;
}
</script>
</head>
<body>
  <form action="login.php" method="post" onsubmit="return validate()">
    Username: <input type="text" id="username" name="username"><br><br>
    Password: <input type="password" id="password" name="password"><br><br>
    <input type="submit" value="Submit">
  </form>
</body>
</html>

The form is submitted only when validate() returns true.

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2018 AD · 4 marks

Write a complete XHTML code to demonstrate a nested table.

Answer

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
  <title>Nested Table</title>
  <style type="text/css">
    table, td, th { border: 1px solid black; border-collapse: collapse; padding: 5px; }
  </style>
</head>
<body>
  <table>
    <tr>
      <th>Name</th>
      <th>Marks</th>
    </tr>
    <tr>
      <td>Ram</td>
      <td>
        <table>
          <tr>
            <th>Subject</th>
            <th>Score</th>
          </tr>
          <tr>
            <td>Web Technology</td>
            <td>78</td>
          </tr>
          <tr>
            <td>Accounting</td>
            <td>85</td>
          </tr>
        </table>
      </td>
    </tr>
  </table>
</body>
</html>

The inner table is placed inside a <td> cell of the outer table.

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2018 AD · 4 marks

Write a java script function Check Square that takes two arguments for length and breadth. The function returns "The object is square if length and breadth are equal else returns rectangle".

Answer

function checkSquare(length, breadth) {
  if (length === breadth) {
    return "The object is square";
  } else {
    return "The object is rectangle";
  }
}

document.write(checkSquare(5, 5));  // The object is square
document.write(checkSquare(5, 8));  // The object is rectangle

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2018 AD · 4 marks

Write a complete XHTML source code to create a web form that contains a textbox, a textarea, a select box, radio buttons, a submit button a radio button.

Answer

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
  <title>Web Form</title>
</head>
<body>
  <form action="process.php" method="post">
    <p>Name: <input type="text" name="name" /></p>
    <p>Comments:<br />
      <textarea name="comments" rows="4" cols="30"></textarea></p>
    <p>Course:
      <select name="course">
        <option value="bim">BIM</option>
        <option value="bbs">BBS</option>
        <option value="bca">BCA</option>
      </select></p>
    <p>Gender:
      <input type="radio" name="gender" value="male" /> Male
      <input type="radio" name="gender" value="female" /> Female</p>
    <p><input type="submit" value="Submit" /></p>
  </form>
</body>
</html>

All tags are lower case, properly nested and closed, and attribute values are quoted, as XHTML requires.

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2018 AD · 5 marks

What do you mean by URL? Differentiate between absolute and relative URL. Write an example for linking to the files in same directory, sub directory, parent directory and form the root directory.

Answer

URL (Uniform Resource Locator) is the address of a resource on the web. It has the form protocol://domain/path/file, for example https://www.example.com/images/logo.png.

Absolute vs relative URL:

Absolute URLRelative URL
Gives the complete address including protocol and domain.Gives the path relative to the current page's location.
Works from any page or site.Works only within the same site.
Example: https://www.example.com/pages/about.htmlExample: pages/about.html
Needed to link to external sites.Easier to maintain and move with the site.

Examples of linking:

  • Same directory: <a href="about.html">About</a>
  • Sub directory: <a href="images/photo.jpg">Photo</a>
  • Parent directory: <a href="../index.html">Home</a>
  • From the root directory: <a href="/css/style.css">Style</a> (starts with /, so the path is taken from the site root)

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2018 AD · 5 marks

Write short notes on:
a. Whitespace collapsing b. GET vs POST c. Importance of alt attribute, d. Sibling Selector e. Bold vs Strong tag

Answer

(a) Whitespace collapsing: browsers merge multiple consecutive spaces, tabs and line breaks in HTML source into a single space when displaying text. Extra spacing in code therefore does not appear on the page. To keep spacing use &nbsp;, <br>, <pre> or CSS white-space: pre.

(b) GET vs POST: GET appends data to the URL as a query string (page.php?name=ram), so it is visible, limited in length, can be bookmarked and is suited to searches. POST sends data in the request body, so it is hidden, has no practical size limit and is used for sensitive data, large forms and uploads.

(c) Importance of alt attribute: alt gives alternative text for an image. It is shown if the image fails to load, is read by screen readers for visually impaired users, helps search engines understand the image, and is required for valid XHTML. Example: <img src="logo.png" alt="Company logo">.

(d) Sibling selector: selects elements that share the same parent. The adjacent sibling selector A + B selects the B immediately following A, and the general sibling selector A ~ B selects all B siblings after A.

h1 + p { color: red; }
h1 ~ p { font-style: italic; }

(e) Bold vs Strong tag: <b> only makes text visually bold, with no extra meaning. <strong> marks text as having strong importance; it is usually shown bold too, but screen readers can emphasise it, so it is preferred for accessibility and semantics.

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2019 AD · 1 mark

What is box modeling in HTML?

Answer

The CSS box model treats every HTML element as a rectangular box made of four layers, from inside to outside:

  1. Content: the text or image.
  2. Padding: space around the content, inside the border.
  3. Border: a line around the padding.
  4. Margin: transparent space outside the border, separating the element from others.
div { width: 200px; padding: 10px; border: 2px solid black; margin: 15px; }

The total width of this box is 200+2(10)+2(2)=224200 + 2(10) + 2(2) = 224 px, excluding margins.

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2019 AD · 1 mark

Write any three methods to access HTML element from JavaScript?

Answer

Three methods to access an HTML element from JavaScript:

  1. document.getElementById("id") returns the element with the given id.
  2. document.getElementsByClassName("class") or document.getElementsByTagName("p") returns a collection of matching elements.
  3. document.querySelector("#id or .class or tag") returns the first element matching a CSS selector (querySelectorAll returns all).
var h = document.getElementById("title");
h.innerHTML = "New heading";

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2019 AD · 1 mark

What are different ways to use CSS?

Answer

CSS can be used in three ways:

  • Inline: using the style attribute, e.g. <p style="color:red;">Text</p>.
  • Internal: using a <style> element in the <head>, e.g. <style> p { color: red; } </style>.
  • External: a separate .css file linked with <link rel="stylesheet" href="style.css"> in the <head>. This is best for sharing one style across many pages.

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2019 AD · 1 mark

Write two different units to change font size in CSS.

Answer

Two units for font-size:

  • Pixels (px): an absolute unit, e.g. font-size: 16px;
  • em (or %, rem): a relative unit based on the parent's font size, e.g. font-size: 1.5em; makes the text 1.5 times the parent size.

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2019 AD · 1 mark

Which property of CSS is used to make background fixed?

Answer

The background-attachment property with the value fixed makes the background stay fixed while the page scrolls.

body {
  background-image: url("bg.jpg");
  background-attachment: fixed;
}

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2019 AD · 1 mark

What is a tag in HTML?

Answer

A tag is a keyword enclosed in angle brackets that tells the browser how to structure or display content. Most tags come in pairs, an opening tag and a closing tag with a slash, such as <p> and </p>. Some tags are empty (self-closing), such as <br> and <img>. A tag together with its content forms an HTML element.

<h1>Welcome</h1>

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2019 AD · 1 mark

Differentiate between order list and unordered list.

Answer

Ordered listUnordered list
Created with <ol>.Created with <ul>.
Items are numbered or lettered (1, 2, 3 / a, b, c / i, ii, iii).Items are marked with bullets (disc, circle, square).
Used where order matters, such as steps.Used where order does not matter.
type attribute sets the numbering style.list-style-type sets the bullet style.

Both use <li> for each item.

<ol><li>Boil water</li><li>Add tea</li></ol>
<ul><li>Milk</li><li>Sugar</li></ul>

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2019 AD · 1 mark

How do you create image as a link in HTML?

Answer

Place the <img> tag inside an anchor <a> tag, so that clicking the image opens the link.

<a href="https://www.example.com">
  <img src="logo.png" alt="Visit Example" width="120" height="60">
</a>

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2019 AD · 1 mark

Write a code to use external JavaScript in a page.

Answer

Save the script in a separate file, e.g. script.js:

function greet() {
  alert("Hello from external JavaScript");
}

Then link it using the src attribute of the <script> tag:

<!DOCTYPE html>
<html>
<head>
  <title>External JS</title>
  <script src="script.js"></script>
</head>
<body>
  <button onclick="greet()">Click me</button>
</body>
</html>

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2019 AD · 1 mark

How string is converted to number in JavaScript?

Answer

JavaScript converts strings to numbers with:

  • parseInt(str): gives an integer, stopping at the first non-digit character; parseInt("42px") gives 42.
  • parseFloat(str): gives a decimal number; parseFloat("3.14abc") gives 3.14.
  • Number(str): converts the whole string; Number("25") gives 25, and Number("abc") gives NaN.
  • The unary plus: +"10" gives 10.

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2019 AD · 4 marks

Write a JavaScript program to add odd numbers of a list.

Answer

The program below goes through the list (array), picks the odd numbers using the remainder operator % and adds them.

<!DOCTYPE html>
<html>
<body>
<script>
var list = [12, 7, 3, 20, 15, 8, 9];
var sum = 0;
for (var i = 0; i < list.length; i++) {
    if (list[i] % 2 !== 0) {      // odd number
        sum += list[i];
    }
}
document.write("List: " + list.join(", ") + "<br>");
document.write("Sum of odd numbers = " + sum);
</script>
</body>
</html>

For the list above the odd numbers are 7, 3, 15 and 9, so the output is Sum of odd numbers = 34.

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2019 AD · 4 marks

Differentiate between child selector and descendent selector with example.

Answer

Child selectorDescendant selector
Written with the > symbol: parent > childWritten with a space: ancestor descendant
Selects only elements that are direct children of the parentSelects elements nested at any level inside the ancestor (children, grandchildren, ...)
More specific and restrictiveWider in scope

Example

<style>
div > p { color: red; }     /* child selector */
div p   { font-weight: bold; } /* descendant selector */
</style>
<div>
  <p>Paragraph 1 (direct child)</p>
  <section>
    <p>Paragraph 2 (grandchild)</p>
  </section>
</div>

Here div > p colours only Paragraph 1 red, whereas div p makes both Paragraph 1 and Paragraph 2 bold.

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2019 AD · 4 marks

Write a JavaScript program that takes string from user and display in reverse order.

Answer

<!DOCTYPE html>
<html>
<body>
<script>
var str = prompt("Enter a string:");
var reversed = "";
for (var i = str.length - 1; i >= 0; i--) {
    reversed += str.charAt(i);
}
document.write("Original string: " + str + "<br>");
document.write("Reversed string: " + reversed);
</script>
</body>
</html>

The program reads the string with prompt(), then a loop runs from the last character to the first and appends each character to a new string. (A shorter alternative is str.split("").reverse().join("").) For input Nepal the output is lapeN.

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2019 AD · 4 marks

Make form with name, address, email and password, then validate values for empty and correct values using JavaScript.

Answer

<!DOCTYPE html>
<html>
<head>
<title>Form Validation</title>
<script>
function validate() {
    var name = document.getElementById("name").value.trim();
    var address = document.getElementById("address").value.trim();
    var email = document.getElementById("email").value.trim();
    var pass = document.getElementById("password").value;

    if (name === "" || address === "" || email === "" || pass === "") {
        alert("All fields are required.");
        return false;
    }
    var emailPattern = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
    if (!emailPattern.test(email)) {
        alert("Enter a valid email address.");
        return false;
    }
    if (pass.length < 6) {
        alert("Password must be at least 6 characters long.");
        return false;
    }
    if (!/^[A-Za-z ]+$/.test(name)) {
        alert("Name must contain letters only.");
        return false;
    }
    alert("Form submitted successfully.");
    return true;
}
</script>
</head>
<body>
<form onsubmit="return validate()">
    Name: <input type="text" id="name"><br><br>
    Address: <input type="text" id="address"><br><br>
    Email: <input type="text" id="email"><br><br>
    Password: <input type="password" id="password"><br><br>
    <input type="submit" value="Submit">
</form>
</body>
</html>

On submit, validate() checks that no field is empty, that the email matches a regular expression, that the name has only letters and that the password has at least 6 characters. Returning false stops the form from being submitted.

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2019 AD · 4 marks

Create page with following layout without using table tag. (A layout with div1 on top, div3 and div4 side by side below it, div5 at the bottom, and div2 as a tall column on the right is given in a figure in the original paper.)

Answer

The layout is built with div elements and CSS float (no table tag): div1 on top, div3 and div4 side by side below it on the left, div5 at the bottom, and div2 as a tall column on the right.

<!DOCTYPE html>
<html>
<head>
<style>
#wrapper { width: 800px; margin: auto; }
div { border: 1px solid #333; box-sizing: border-box; }
#div1 { height: 80px; }
#left { width: 70%; float: left; }
#div3 { width: 50%; float: left; height: 200px; }
#div4 { width: 50%; float: left; height: 200px; }
#div2 { width: 30%; float: left; height: 280px; }
#div5 { clear: both; height: 80px; }
</style>
</head>
<body>
<div id="wrapper">
  <div id="div1">div1</div>
  <div id="left">
    <div id="div3">div3</div>
    <div id="div4">div4</div>
  </div>
  <div id="div2">div2</div>
  <div id="div5">div5</div>
</div>
</body>
</html>

float: left places the boxes side by side and clear: both makes div5 start below all the floated boxes.

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2019 AD · 5 marks

What are the advantages of CSS? Explain with examples

Answer

CSS (Cascading Style Sheets) separates the presentation of a web page from its HTML content.

Advantages

  1. Separation of content and design: HTML holds the structure and CSS holds the look, so both are easier to maintain.
  2. Reusability and consistency: one external style sheet can control the look of many pages, so the whole site is uniform.
  3. Easy maintenance: changing one rule in the style sheet updates every page that uses it.
  4. Faster page loading: the CSS file is cached by the browser and less formatting markup is repeated in each page.
  5. More formatting options: effects such as shadows, gradients, animations, positioning and layouts are possible that plain HTML cannot do.
  6. Device and media independence: media queries let the same page adapt to screens, mobiles and print.
  7. Better accessibility and SEO: clean HTML is easier for search engines and screen readers.

Example

<link rel="stylesheet" href="style.css">
/* style.css */
h1 { color: navy; text-align: center; }
p  { font-family: Arial; font-size: 16px; }

Every page linked to style.css shows navy centred headings and Arial paragraphs. Changing navy to green in this one file changes all the pages.

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2019 AD · 5 marks

What is scripting language? Explain why is JavaScript become more and more popular these days.

Answer

A scripting language is a programming language that is interpreted (run line by line by another program such as a browser or server) instead of being compiled into a separate executable. It is mostly used to automate tasks and to add behaviour to existing applications. Examples: JavaScript, PHP, Python, Perl.

Why JavaScript is becoming more and more popular

  1. Runs in every browser: no installation or plug-in is needed; it is the standard client-side language of the web.
  2. Interactive pages: form validation, menus, animation, and updating content without reloading (AJAX).
  3. Easy to learn: simple syntax, loosely typed and quick to test.
  4. Full-stack use: with Node.js it also runs on the server, so one language is used for front end and back end.
  5. Huge ecosystem: libraries and frameworks such as jQuery, React, Angular and Vue, plus npm packages.
  6. Reduced server load: validation and processing are done on the client side.
  7. Wide use beyond the web: mobile apps, desktop apps and games.
  8. Strong community and support from all major browser vendors.

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2021 AD · 10 marks

What do you mean by a list? Explain different types of lists with an example for each.

Answer

A list in HTML is a group of related items shown one after another, each item usually starting on a new line with a marker such as a bullet or number. Lists are used for menus, steps, definitions, etc.

HTML has three types of lists.

1. Ordered list (<ol>): items are numbered (1, 2, 3 or a, b, c or I, II, III). Each item is written in <li>. The type attribute changes the numbering style.

<ol type="1">
  <li>Wake up</li>
  <li>Study</li>
  <li>Sleep</li>
</ol>

2. Unordered list (<ul>): items are shown with bullets (disc, circle or square).

<ul>
  <li>Rice</li>
  <li>Lentils</li>
  <li>Vegetables</li>
</ul>

3. Definition (description) list (<dl>): a list of terms with their descriptions. <dt> holds the term and <dd> its description.

<dl>
  <dt>HTML</dt>
  <dd>Language used to create web pages</dd>
  <dt>CSS</dt>
  <dd>Language used to style web pages</dd>
</dl>

Lists can also be nested by placing one <ul> or <ol> inside an <li> of another list.

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2021 AD · 10 marks

List the differences between absolute and relative URLs. Write code for linking the files in same directory, sub directory, parent directory and root directory.

Answer

Differences between absolute and relative URLs

Absolute URLRelative URL
Gives the complete address including protocol and domain, e.g. https://www.example.com/images/pic.jpgGives the path only relative to the current page, e.g. images/pic.jpg
Works from anywhereWorks only inside the same site/folder structure
Used to link to other websitesUsed to link pages and files of the same website
Longer, and must be changed if the domain changesShorter, and the site can be moved to another domain without changes
Slightly slower to resolveFaster and easier to maintain

Linking files with relative paths

<!-- 1. File in the same directory -->
<a href="about.html">About</a>

<!-- 2. File in a sub directory (folder inside the current one) -->
<a href="pages/contact.html">Contact</a>
<img src="images/logo.png" alt="Logo">

<!-- 3. File in the parent directory (one level up) -->
<a href="../index.html">Home</a>

<!-- 4. File from the root directory of the site -->
<a href="/css/style.css">Root file</a>
<link rel="stylesheet" href="/css/style.css">

../ moves one folder up (use ../../ for two levels), and a leading / always starts from the root folder of the website.

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2021 AD · 10 marks

Explain selectors and its types with example.

Answer

A CSS selector is the part of a CSS rule that tells the browser which HTML elements the style declarations apply to.

selector { property: value; }

Types of selectors

  1. Universal selector (*): selects all elements.
    * { margin: 0; padding: 0; }
    
  2. Element (type) selector: selects all elements of a given tag.
    p { color: blue; }
    
  3. Class selector (.): selects elements with the given class; can be used on many elements.
    .note { background: yellow; }      /* <p class="note"> */
    
  4. ID selector (#): selects the one element with the given id (must be unique).
    #header { height: 80px; }          /* <div id="header"> */
    
  5. Group selector (,): applies the same style to several selectors.
    h1, h2, p { font-family: Arial; }
    
  6. Descendant selector (space): elements nested at any level inside another.
    div p { color: red; }
    
  7. Child selector (>): only direct children.
    ul > li { list-style: square; }
    
  8. Adjacent sibling selector (+): the element immediately after another.
    h1 + p { font-weight: bold; }
    
  9. Attribute selector ([ ]): elements having an attribute or value.
    input[type="text"] { border: 1px solid gray; }
    
  10. Pseudo-class selector (:): an element in a special state.
    a:hover { color: red; }
    
  11. Pseudo-element selector (::): a part of an element.
    p::first-line { font-weight: bold; }
    

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2021 AD · 10 marks

Write source code to generate the following layout using divs. (A page layout with two stacked top boxes, three columns in the middle and a footer box is given in a figure in the original paper.)

Answer

The layout has two stacked boxes at the top, three columns in the middle and a footer box. It is made with div elements and CSS.

<!DOCTYPE html>
<html>
<head>
<title>Div Layout</title>
<style>
#container { width: 900px; margin: 0 auto; }
.box { border: 1px solid #000; box-sizing: border-box; text-align: center; }
#top1 { height: 70px; background: #e0e0e0; }
#top2 { height: 50px; background: #cfd8dc; }
#col1 { width: 20%; height: 250px; float: left; background: #ffe0b2; }
#col2 { width: 60%; height: 250px; float: left; background: #fff9c4; }
#col3 { width: 20%; height: 250px; float: left; background: #c8e6c9; }
#footer { clear: both; height: 60px; background: #b3e5fc; }
</style>
</head>
<body>
<div id="container">
    <div class="box" id="top1">Header</div>
    <div class="box" id="top2">Navigation</div>
    <div class="box" id="col1">Left column</div>
    <div class="box" id="col2">Middle column</div>
    <div class="box" id="col3">Right column</div>
    <div class="box" id="footer">Footer</div>
</div>
</body>
</html>

The three middle columns are floated left with widths adding up to 100%, and clear: both on the footer places it below them.

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2021 AD · 10 marks

What are the factors to be considered while designing, page layout? Explain.

Answer

Page layout is the arrangement of text, images, menus and other elements on a web page. The following factors should be considered when designing it.

  1. Purpose and target audience: the layout should suit the goal of the site (information, shopping, news) and the users' age, skills and needs.
  2. Consistency: the same header, navigation, colours, fonts and style on all pages so users feel familiar.
  3. Navigation: clear, easy and visible menus, links and breadcrumbs so any page can be reached in few clicks.
  4. Visual hierarchy and balance: important content (headings, logo, call-to-action) should be placed prominently, with balanced use of white space.
  5. Readability: suitable font type and size, good contrast between text and background, short lines and proper spacing.
  6. Colour scheme: a limited, pleasant palette that matches the brand and remains readable.
  7. Responsiveness / screen size: the page should adapt to desktop, tablet and mobile screens and various resolutions (use fluid widths and media queries).
  8. Loading time: optimised images and light code so pages open quickly.
  9. Browser and device compatibility: the layout should work in all major browsers.
  10. Accessibility: alt text for images, keyboard access and support for screen readers.
  11. Content organisation: grouping related content, using headings, lists and sections.
  12. Use of standards: clean HTML/CSS (divs and CSS rather than tables) for easy maintenance and SEO.

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2021 AD · 10 marks

Explain the usage of the following CSS properties: z-index, margin, display, color, float.

Answer

1. z-index: sets the stacking order of positioned elements (those with position other than static). An element with a higher value appears in front of one with a lower value. It can be negative.

#box1 { position: absolute; z-index: 1; }
#box2 { position: absolute; z-index: 2; }   /* box2 appears above box1 */

2. margin: sets the space outside the border of an element, between it and neighbouring elements. It can be given for each side (margin-top, margin-right, margin-bottom, margin-left) or in shorthand; margin: 0 auto; centres a block element horizontally.

p { margin: 10px 20px 10px 20px; }   /* top right bottom left */

3. display: controls how an element is shown. Common values: block (starts a new line and takes full width), inline (flows within text), inline-block, flex, grid and none (hides the element and removes its space).

span.big { display: block; }
.hidden { display: none; }

4. color: sets the colour of the text of an element, using a name, hex code, rgb() or hsl() value.

h1 { color: #ff0000; }      /* red heading */
p  { color: rgb(0, 0, 255); }

5. float: moves an element to the left or right of its container so that text and inline content wrap around it. Values are left, right and none. It is used for images and multi-column layouts, and clear is used to stop wrapping.

img { float: right; margin: 5px; }
footer { clear: both; }

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2021 AD · 10 marks

Write source code to generate the following form using JavaScript. (A form with Name text box, Country drop-down, Gender (Male / Female radio buttons) and About text area.)

Answer

The form is generated by JavaScript using DOM methods, so the HTML body is empty.

<!DOCTYPE html>
<html>
<head><title>Form using JavaScript</title></head>
<body>
<div id="container"></div>
<script>
var form = document.createElement("form");

// Name text box
form.appendChild(document.createTextNode("Name: "));
var name = document.createElement("input");
name.type = "text";
name.name = "name";
form.appendChild(name);
form.appendChild(document.createElement("br"));
form.appendChild(document.createElement("br"));

// Country drop-down
form.appendChild(document.createTextNode("Country: "));
var country = document.createElement("select");
["Nepal", "India", "China", "Bhutan"].forEach(function (c) {
    var opt = document.createElement("option");
    opt.value = c;
    opt.text = c;
    country.appendChild(opt);
});
form.appendChild(country);
form.appendChild(document.createElement("br"));
form.appendChild(document.createElement("br"));

// Gender radio buttons
form.appendChild(document.createTextNode("Gender: "));
["Male", "Female"].forEach(function (g) {
    var r = document.createElement("input");
    r.type = "radio";
    r.name = "gender";
    r.value = g;
    form.appendChild(r);
    form.appendChild(document.createTextNode(g + " "));
});
form.appendChild(document.createElement("br"));
form.appendChild(document.createElement("br"));

// About text area
form.appendChild(document.createTextNode("About: "));
var about = document.createElement("textarea");
about.rows = 4;
about.cols = 30;
form.appendChild(about);

document.getElementById("container").appendChild(form);
</script>
</body>
</html>

createElement() makes each control, its properties are set, and appendChild() adds it to the form, which is finally inserted into the page.

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2021 AD · 10 marks

What is JavaScript? Write a program in JavaScript to add elements of an array.

Answer

JavaScript is a lightweight, interpreted, object-based scripting language that is embedded in HTML pages and run by the web browser. It is used to make web pages interactive, for example validating forms, handling events, changing page content dynamically and communicating with the server (AJAX). With Node.js it can also run on the server.

Program to add the elements of an array

<!DOCTYPE html>
<html>
<body>
<script>
var arr = [10, 20, 30, 40, 50];
var sum = 0;
for (var i = 0; i < arr.length; i++) {
    sum = sum + arr[i];
}
document.write("Array elements: " + arr.join(", ") + "<br>");
document.write("Sum = " + sum);
</script>
</body>
</html>

Output: Sum = 150.

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

Questions from TU BIM Third Semester Model Questions 2023 (IT 237, ACC 201, IT 236, STT 201, IT 238) (Faculty of Management model question set 2023, BIM third semester (new course)), TU BIM Third Semester Model Question 2023 ACC 201 Financial Accounting (Faculty of Management model question 2023), TU BIM Third Semester Model Question 2023 IT 236 Microprocessor and Computer Architecture (Faculty of Management model question 2023), TU BIM Third Semester Model Question 2023 STT 201 Business Statistics (Faculty of Management model question 2023), TU BIM Third Semester Model Question 2023 IT 238 Data Structure and Algorithms (Faculty of Management model question 2023), TU BIM Third Semester Model Question 2023 STT 201 Business Statistics (Lab) (Faculty of Management model question 2023, MS-Excel practical), TU BIM 2014 Third Semester IT 215 Web Programming I (model question) (Faculty of Management model question 2014 (old course), via EducateNepal), TU BIM 2014 Third Semester IT 216 Java Programming I (model question) (Faculty of Management model question 2014 (old course), via EducateNepal), TU BIM 2014 Third Semester IT 217 Computer Organization (model question) (Faculty of Management model question 2014 (old course), via EducateNepal), TU BBA/BIM/BBM 2015 Third Semester STT 201 Business Statistics (model question) (Faculty of Management model question 2015 (old course), via EducateNepal), TU BBA/BIM/BBM 2015 Third Semester STT 201 Business Statistics Lab (model question) (Faculty of Management model question 2015, lab work using MS-Excel), TU BIM Computer Organization (IT 217) 2012 AD (Board exam paper, 2012 AD), TU BIM Computer Organization (IT 217) 2014 AD (Board exam paper, 2014 AD), TU BIM Computer Organization (IT 217) 2015 AD (Board exam paper, 2015 AD), TU BIM Computer Organization (IT 217) 2016 AD (Board exam paper, 2016 AD), TU BIM Computer Organization (IT 217) 2017 AD (Board exam paper, 2017 AD), TU BIM Computer Organization (IT 217) 2018 AD (Board exam paper, 2018 AD), TU BIM Computer Organization (IT 217) 2019 AD (Board exam paper, 2019 AD), TU BIM Computer Organization (IT 217) 2021 AD (Board exam paper, 2021 AD), TU BIM Web Programming I (IT 215) 2014 AD (Board exam paper, 2014 AD), TU BIM Web Programming I (IT 215) 2015 AD (Board exam paper, 2015 AD), TU BIM Web Programming I (IT 215) 2016 AD (Board exam paper, 2016 AD), TU BIM Web Programming I (IT 215) 2017 AD (Board exam paper, 2017 AD), TU BIM Web Programming I (IT 215) 2018 AD (Board exam paper, 2018 AD), TU BIM Web Programming I (IT 215) 2019 AD (Board exam paper, 2019 AD), TU BIM Web Programming I (IT 215) 2021 AD (Board exam paper, 2021 AD), TU BIM Java Programming I (IT 216) 2015 AD (Board exam paper, 2015 AD), TU BIM Java Programming I (IT 216) 2017 AD (Board exam paper, 2017 AD), TU BIM Java Programming I (IT 216) 2018 AD (Board exam paper, 2018 AD), TU BIM Java Programming I (IT 216) 2019 AD (Board exam paper, 2019 AD), TU BIM Java Programming I (IT 216) 2021 AD (Board exam paper, 2021 AD), TU BIM Business Statistics (STT 201) 2009 AD (Board exam paper, 2009 AD), TU BIM Business Statistics (STT 201) 2010 AD (Board exam paper, 2010 AD), TU BIM Business Statistics (STT 201) 2021 AD (Board exam paper, January 2021 (Full Marks 36, answer any six)), TU BIM Business Statistics (STT 201) 2013 AD (Board exam paper, 2013 (Full Marks 36)), TU BIM Business Statistics (STT 201) 2014 AD (Board exam paper, 2014 AD), TU BIM Business Statistics (STT 201) 2015 AD (Board exam paper, 2015 AD), TU BIM Business Statistics (STT 201) 2016 AD (Board exam paper, 2016 AD), TU BIM Business Statistics (STT 201) 2018 AD (Board exam paper, 2018 AD), TU BIM Business Statistics (STT 201) 2019 AD (Board exam paper, 2019 AD), TU BIM Financial Accounting (ACC 201) 2015 AD (Board exam paper, 2015 AD), TU BIM Financial Accounting (ACC 201) 2016 AD (Board exam paper, 2016 AD), TU BIM Financial Accounting (ACC 201) 2017 AD (Board exam paper, 2017 AD), TU BIM Financial Accounting (ACC 201) 2018 AD (Board exam paper, 2018 AD), TU BIM Financial Accounting (ACC 201) 2019 AD (Board exam paper, 2019 AD), TU BIM Financial Accounting (ACC 201) 2021 AD (Board exam paper, 2021 AD), TU BIM Financial Accounting (ACC 201) 2014 AD (Board exam paper, 2014 AD), TU BIM Financial Accounting (ACC 201) 2013 AD (Board exam paper, 2013 AD), TU BIM Financial Accounting (ACC 201) 2012 AD (Board exam paper, 2012 AD), TU BIM Financial Accounting (ACC 201) 2010 AD (Board exam paper, 2010 AD) and TU BIM Financial Accounting (ACC 201) 2009 AD (Board exam paper, 2009 AD). Answers are written for this site; check them against your class notes.