FBISE Compter Notes Chapter 3 (Programming Fundamentals)
FBISE Compter Notes Chapter 3 (Programming Fundamentals)
4. List out the frequent tags used in text of a webpage and what are they used
for?
Answer:
Common HTML tags for text formatting and their uses:
1. <p>: Defines a paragraph.
2. <h1> to <h6>: Headings, with <h1> being the largest and <h6> the smallest.
3. <b> or <strong>: Makes text bold.
4. <i> or <em>: Makes text italicized or emphasized.
5. <u>: Underlines the text.
6. <br>: Inserts a line break.
7. Infer about the External CSS? Where are External CSS generally used?
Answer:
- External CSS: External CSS is a separate file containing CSS rules. It is linked to HTML using the
<link> tag in the <head> section.
- Usage: External CSS is generally used to maintain consistency across multiple web pages and to
improve code organization.
Example:
1. CSS File: style.css
body {
background-color: lightblue;
}
2. HTML Linking:
<link rel="stylesheet" href="style.css">
Answer:
The Document Object Model (DOM) is a programming interface for HTML and XML documents. It
represents the structure of a document as a tree of objects, where each object corresponds to an
element in the document. The DOM allows developers to interact with and manipulate webpage
content dynamically using programming languages like JavaScript.
• It allows dynamic updates, such as changing content, style, or structure of the webpage.
Example:
<!DOCTYPE html>
<html>
<head>
<title>DOM Example</title>
</head>
<body>
<script>
function changeText() {
</script>
</body>
</html>
Explanation:
• In this example, the DOM tree includes the <html>, <head>, <body>, <h1>, <p>, and
<button> elements as nodes.
• When the button is clicked, JavaScript dynamically accesses the <h1> element using
document.getElementById("heading") and updates its content to "Hello, DOM!".
Output:
Before clicking: "Hello, World!"
After clicking: "Hello, DOM!"
Answer:
HTML provides six levels of headings, <h1> to <h6>, where <h1> is the largest and <h6> is the
smallest.
Code Example:
<!DOCTYPE html>
<html>
<head>
<title>HTML Headings</title>
</head>
<body>
</body>
</html>
Explanation:
• <h1> is used for the most important heading and appears the largest.
Output:
The headings will be displayed in decreasing font size from <h1> to <h6>.
Answer:
To load a background image in a webpage using CSS, follow these steps:
3. Step 3: Link the CSS file to the HTML file or use inline or internal CSS.
Code Example:
<!DOCTYPE html>
<html>
<head>
<style>
body {
background-image: url("background.jpg");
background-repeat: no-repeat;
</style>
</head>
<body>
<h1>Welcome to My Website</h1>
</body>
</html>
Explanation:
4. With the help of sample code, highlight different methods to incorporate CSS code in a HTML
webpage.
Answer:
There are three main methods to incorporate CSS in an HTML webpage:
3. Internal CSS: CSS is written inside the <style> tag in the <head> section.
4. <!DOCTYPE html>
5. <html>
6. <head>
7. <style>
8. p{
9. color: green;
11. }
12. </style>
13. </head>
14. <body>
16. </body>
17. </html>
18. External CSS: CSS is written in a separate file and linked to the HTML file.
CSS File (style.css):
19. p {
22. }
HTML File:
<!DOCTYPE html>
<html>
<head>
</head>
<body>
</body>
</html>
Explanation:
• External CSS: Recommended for large projects to maintain consistency across multiple
webpages.
5. Sketch steps and provide code to apply border and color to a table in a webpage.
Answer:
To apply borders and colors to a table using CSS, follow these steps:
2. Step 2: Use CSS to add borders and colors to the table, rows, and cells.
Code Example:
<!DOCTYPE html>
<html>
<head>
<style>
table {
border-collapse: collapse;
width: 50%;
th, td {
text-align: center;
padding: 8px;
th {
background-color: lightblue;
td {
background-color: lightyellow;
</style>
</head>
<body>
<h1>Styled Table</h1>
<table>
<tr>
<th>Name</th>
<th>Age</th>
</tr>
<tr>
<td>Ali</td>
<td>20</td>
</tr>
<tr>
<td>Fatima</td>
<td>22</td>
</tr>
</table>
</body>
</html>
Explanation:
• background-color: Adds color to the header (th) and data (td) cells.
Output:
A table with a black border, light blue header, and light yellow cells.
6. Discuss the functionality JavaScript can provide in a webpage with the help of suitable example
code.
Answer:
JavaScript is a programming language that adds interactivity and dynamic functionality to
webpages. It enables features like animations, event handling, data validation, and DOM
manipulation.
3. Form validation.
<!DOCTYPE html>
<html>
<head>
<title>JavaScript Example</title>
</head>
<body>
<h1>JavaScript Functionality</h1>
<script>
function showMessage() {
</script>
</body>
</html>
Explanation:
• When the button is clicked, the onclick event triggers the showMessage() function.
• The function displays an alert box with the message "Hello! This is a JavaScript example."
Answer:
To create scrolling text on a webpage, you can use the <marquee> tag (deprecated) or CSS
animations for a modern approach.
Code Example:
<!DOCTYPE html>
<html>
<head>
<style>
.scrolling-text {
width: 100%;
overflow: hidden;
white-space: nowrap;
box-sizing: border-box;
.scrolling-text p {
display: inline-block;
padding-left: 100%;
@keyframes scroll-left {
0% {
transform: translateX(0);
100% {
transform: translateX(-100%);
</style>
</head>
<body>
<div class="scrolling-text">
</div>
</body>
</html>
Explanation:
• The text scrolls continuously from right to left using the transform: translateX property.
8. Enlist steps to add a video clip in a website which starts playing as the web page loads.
Answer:
To add a video clip to a website that starts playing when the webpage loads, follow these steps:
3. Include the loop attribute if you want the video to replay continuously.
4. Use the controls attribute to provide play, pause, and volume options (optional).
Code Example:
<!DOCTYPE html>
<html>
<head>
<title>Auto-Playing Video</title>
</head>
<body>
<h1>Welcome to My Website</h1>
</video>
</body>
</html>
Explanation:
• The autoplay attribute starts the video as soon as the webpage loads.
• muted ensures the video plays without sound initially (required by modern browsers for
autoplay).
9. Cite steps on compiling the result of your last examination in a tabular form and display it in a
webpage.
Answer:
Code Example:
<!DOCTYPE html>
<html>
<head>
<title>Examination Results</title>
<style>
table {
width: 50%;
border-collapse: collapse;
th, td {
text-align: center;
padding: 8px;
th {
background-color: lightblue;
td {
background-color: lightyellow;
</style>
</head>
<body>
<table>
<tr>
<th>Subject</th>
<th>Marks</th>
</tr>
<tr>
<td>Mathematics</td>
<td>90</td>
</tr>
<tr>
<td>Science</td>
<td>85</td>
</tr>
<tr>
<td>English</td>
<td>88</td>
</tr>
</table>
</body>
</html>
Explanation:
10. In context of Fig. 40(d), add another button namely 'Revert' which when pressed, it will reverse
both the color and index values.
Answer:
To add a "Revert" button that reverses the color and index values, use JavaScript to change styles
dynamically.
Code Example:
<!DOCTYPE html>
<html>
<head>
<style>
.box {
width: 200px;
height: 100px;
text-align: center;
line-height: 100px;
background-color: lightblue;
color: black;
</style>
</head>
<body>
<button onclick="revertChanges()">Revert</button>
<script>
function revertChanges() {
box.style.backgroundColor = "black";
box.style.color = "white";
box.innerHTML = "Reverted";
</script>
</body>
</html>
Explanation:
• The onclick event on the "Revert" button calls the revertChanges() function.
• The function dynamically changes the box's background color, text color, and inner content
using style and innerHTML.
3.1 Introduction
1. What is programming?
Programming is the process of writing instructions (code) for a computer to perform specific tasks.
These instructions are written in programming languages like C, Python, or Java.
3.2 HTML
1. What is HTML and what does it stand for?
HTML stands for HyperText Markup Language. It is used to create the structure and content of
webpages.
3.4 JavaScript
1. What is JavaScript and why is it important?
JavaScript is a programming language that adds interactivity and dynamic behavior to webpages. It is
important for handling events, creating animations, and validating forms.
<script src="script.js"></script>
```
2. Describe CSS, its types, and its role in enhancing the appearance of
webpages. Include code examples.
CSS (Cascading Style Sheets) is used to design and style HTML elements. It enhances the webpage's
visual presentation by modifying layout, colors, fonts, and spacing.
Types of CSS:
1. **Inline CSS:** Applied directly to an HTML tag.
```html
<p style="color: blue; font-size: 20px;">This is Inline CSS.</p>
```
2. **Internal CSS:** Defined within the `<style>` tag in the HTML document.
```html
<!DOCTYPE html>
<html>
<head>
<style>
p{
color: green;
font-size: 18px;
}
</style>
</head>
<body>
<p>This is Internal CSS.</p>
</body>
</html>
```
3. **External CSS:** Stored in a separate `.css` file and linked to the HTML file.
Conclusion:
CSS plays a crucial role in creating visually appealing, responsive, and modern websites.
```html
<!DOCTYPE html>
<html>
<head>
<title>Button Click Example</title>
</head>
<body>
<h1>JavaScript Button Click Example</h1>
<p id="output">Original Text</p>
<button onclick="changeText()">Click Me</button>
<script>
function changeText() {
document.getElementById("output").innerHTML = "Text Changed!";
}
</script>
</body>
</html>
```
Importance of JavaScript:
- It makes webpages more engaging and user-friendly.
- It enables real-time updates without refreshing the page (AJAX).
- It is widely used in modern frameworks like React, Angular, and Vue.
2. **Logical Error:** Incorrect logic in code leads to wrong output. Example: Using `+` instead of `-`.
3. **Runtime Error:** Occurs during program execution, like division by zero.
Debugging Tools:
- **Browser Developer Tools:** Use `console.log()` to display output in the browser console.
- **Breakpoints:** Pause code execution to inspect variables.
Output in Console:
```
The value of x is: 5
The value of y is: 10
The sum of x and y is: 15
```
Conclusion:
Debugging ensures that programs run correctly by identifying and fixing errors. Tools like
`console.log` simplify this process, making it easier to inspect code behavior.
MCQS
a) Hyper Transfer Markup Language b) HyperText Markup Language (✓) c) HighText Machine
Language d) None of these
a) To add an image b) To display text in bold c) To set the title of the webpage (✓) d) To
add hyperlinks
a) Using <style> tag b) Using <link> tag (✓) c) Using @import d) None of these
a) Common Style Sheet b) Computer Style Sheet c) Cascading Style Sheets (✓) d) Colorful
Style Sheets
a) Displays an alert box b) Logs messages to the browser console (✓) c) Adds a
breakpoint d) None of these
a) Writing code b) Finding and fixing errors in code (✓) c) Testing websites d) Adding styles
a) A webpage with only images b) A webpage with content that changes dynamically (✓) c) A
webpage with no CSS d) None of these
a) Using the <style> tag b) Using the <script> tag (✓) c) Using the <link> tag d) None of
these
a) Changes the style b) Changes the content of an HTML element (✓) c) Deletes an
element d) None of these