HTML and JavaScript Fundamentals, Exercises of Computer science

Various aspects of web development, including the document object model (dom), html headings, background image integration, css incorporation methods, table styling, and javascript functionalities. It provides detailed explanations, sample code, and step-by-step instructions to help students and developers understand and implement these concepts. Topics such as dynamic content updates, scrolling text, video integration, and tabular data presentation. It serves as a comprehensive resource for understanding the fundamental building blocks of web development, empowering learners to create interactive and visually appealing web pages.

Typology: Exercises

2023/2024

Available from 10/28/2024

amna-altaf-2
amna-altaf-2 ๐Ÿ‡ต๐Ÿ‡ฐ

4 documents

1 / 8

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Ms. Amna Altaf Unit:3 Programming Fundamentals Computer Sc
Unit: 3 Programming Fundamentals
Q1. What is document object model? Explain with the help of an example?
The Document Object Model (DOM) is a programming interface for web documents. It represents the structure of a web
page in a hierarchical tree format, where each element, attribute, and piece of text is a node in this tree. The DOM
allows programming languages like JavaScript to interact with and manipulate the content and structure of web pages
dynamically.
Basic Structure of the DOM:
i. Document: The root node representing the entire document.
ii. Elements: Nodes representing HTML tags, such as <div>, <p>, <a>, etc.
iii. Attributes: Nodes representing attributes of HTML elements, such as class, id, and href.
iv. Text: Nodes representing the text content inside elements.
Example: Consider the following HTML snippet:
<!DOCTYPE html>
<html>
<head>
<title>My Web Page</title>
</head>
<body>
<h1>Welcome to My Web Page</h1>
<p>This is a paragraph.</p>
<a href="https://www.example.com">Click here</a>
</body>
</html>
In this example, the DOM structure would look like this:
Document
โ””โ”€โ”€ html
โ”œโ”€โ”€ head
โ”‚ โ””โ”€โ”€ title
โ”‚ โ””โ”€โ”€ "My Web Page"
โ””โ”€โ”€ body
โ”œโ”€โ”€ h1
โ”‚ โ””โ”€โ”€ "Welcome to My Web Page"
โ”œโ”€โ”€ p
โ”‚ โ””โ”€โ”€ "This is a paragraph."
โ””โ”€โ”€ a
โ”œโ”€โ”€ "Click here"
โ””โ”€โ”€ href="https://www.example.com"
Q2. Write the code to differentiate between different types of headings in HTML.
The <h1> to <h6> tags are used to define HTML headings. <h1> defines the most important heading. <h6> defines the
least important heading. Note: Only use one <h1> per page - this should represent the main heading/subject for the
whole page.
pf3
pf4
pf5
pf8

Partial preview of the text

Download HTML and JavaScript Fundamentals and more Exercises Computer science in PDF only on Docsity!

Unit: 3 Programming Fundamentals

Q1. What is document object model? Explain with the help of an example? The Document Object Model (DOM) is a programming interface for web documents. It represents the structure of a web page in a hierarchical tree format, where each element, attribute, and piece of text is a node in this tree. The DOM allows programming languages like JavaScript to interact with and manipulate the content and structure of web pages dynamically. Basic Structure of the DOM: i. Document: The root node representing the entire document. ii. Elements: Nodes representing HTML tags, such as ,

, , etc. iii. Attributes: Nodes representing attributes of HTML elements, such as class, id, and href. iv. Text: Nodes representing the text content inside elements. Example: Consider the following HTML snippet:

My Web Page

Welcome to My Web Page

This is a paragraph.

Click here

In this example, the DOM structure would look like this: Document โ””โ”€โ”€ html โ”œโ”€โ”€ head โ”‚ โ””โ”€โ”€ title โ”‚ โ””โ”€โ”€ "My Web Page" โ””โ”€โ”€ body โ”œโ”€โ”€ h โ”‚ โ””โ”€โ”€ "Welcome to My Web Page" โ”œโ”€โ”€ p โ”‚ โ””โ”€โ”€ "This is a paragraph." โ””โ”€โ”€ a โ”œโ”€โ”€ "Click here" โ””โ”€โ”€ href="https://www.example.com" Q2. Write the code to differentiate between different types of headings in HTML. The to tags are used to define HTML headings. defines the most important heading. defines the least important heading. Note: Only use one per page - this should represent the main heading/subject for the whole page.

The main keyword of the whole content of a webpage should be display by h1 heading tag.
  • Heading no. 1
  • Heading no. 2
  • Heading no. 3
  • Heading no. 4
  • Heading no. 5
  • Heading no. 6 Q3. Elaborate steps & provide code to load a background image in web page.
    1. Open the HTML file in text editor.
    2. Within the starting tag in your Html file, type
    3. Give the path of the image we want to add. (Example,
    4. Save the Html file in the text editor and run the file. Code:

You can specify background images
for any visible HTML element.

Q4. With the help of sample code, highlight different methods to incorporate CSS code in a HTML page. Ans. Following are the different methods to incorporate CSS code in a HTML page.

  • Inline - by using the style attribute inside HTML elements
  • Internal - by using a
    Q5. Sketch steps & provide code to apply border & color to a table in a web page?

Table With Border

Use the CSS border property to add a border to the table.

Firstname Lastname Age

Zohaib Khan 50

Shoaib Ali 94

Sadia Hussain 80

Q6. Discuss the functionality JavaScript can provide in a web page with the help of suitable example code. Ans. JavaScript is used in development of webpages & scripts. It doesnโ€™t consume much of memory and that is why it is used at the client end in developing websites, for making pages dynamic. JavaScript enhances web pages by enabling dynamic interactions and functionalities. Hereโ€™s a short example illustrating its capabilities: Example: Dynamic Content Update

JavaScript can modify the content of a web page without reloading it. For instance, you can use it to change text or add elements based on user actions. HTML:

What Can JavaScript Do?

JavaScript can change HTML content.

Click Me!

This simple example demonstrates how JavaScript can make web pages interactive and responsive to user actions. Q7. Articulate steps and write code to create a scrolling text on web page.

  1. Create an HTML file with the following code:
  2. Scrolling text on web page will be created. Code:

This is a sample scrolling text that has scrolls in the upper direction.

Note: direction can be up, down, left or right.

Result Name Class & Section

Subject Max Marks Obtained Marks %age

Maths 100 50 50 %

Urdu 75 52 69.4 %

English 75 63 84 %

Q10. In the context of fig. 40(d) , add another button namely โ€œRevertโ€ which when in pressed, it will reverse both color & index values.

Ascending Order