Grade 9 Chapter 3
Grade 9 Chapter 3
1. Define the following terms shortly: www, Internet, HTML, web, website, search engine
WWW (World Wide Web): A system of interlinked hypertext documents and multimedia
accessed through the Internet.
Internet: A global network of interconnected computers that allows for communication
and data exchange.
HTML (Hypertext Markup Language): The standard language used to create and format
documents on the World Wide Web.
Web: The collection of all accessible websites and resources on the World Wide Web.
Website: A collection of related web pages under a single domain name, accessible
through a web browser.
Search Engine: A tool that searches the web to find and display results relevant to user
queries. Examples include Google and Bing.
A static website remains unchanged once created, and its content only updates when the
owner manually modifies it. These sites load directly from the server and are easy to
create and maintain. Once loaded, they don’t require a continuous server connection.
In contrast, a dynamic website updates its content based on user interaction or input,
enhancing visitor engagement. For example, online shopping sites use dynamic elements
to display customized offers, altering the page experience for each user. Dynamic sites
often use scripts like JavaScript, Python, PHP, and ASP.NET to achieve this interactive
functionality, making them adaptable to user preferences.
Back-end development manages server-side functions, using languages like Python and
PHP to handle data and support front-end operations.
19. Write the HTML code to create a hyperlink to "National Book Foundation" that opens in a new
tab.
The HTML code to create a hyperlink to "National Book Foundation" that opens in a new
tab is:
20. How can a video clip be added to a website, and what are its common attributes?
A video clip can be added to a website using the <video> tag. Common attributes
include:
width and height: To specify the video size in pixels.
controls: To enable play, pause, and volume adjustment.
The <source> tag is used within the <video> tag to define the video file and
format. MP4 is the most commonly supported format across browsers.
since it overwrites the webpage if called after the page loads, it is typically avoided in
complex applications in favor of other DOM manipulation methods.
28. What are events in JavaScript, and how are they used?
Events in JavaScript are actions or occurrences, such as a mouse click or keypress, that the script
can detect and respond to. Using event handlers like onclick, developers can trigger specific
functions when an event occurs. This interaction allows webpages to become more dynamic and
responsive to user input.
29. Explain the difference between the alert() and prompt() functions in JavaScript.
The alert() function displays a simple message in a pop-up box to inform the user or provide
feedback. In contrast, the prompt() function not only displays a message but also collects input
from the user. Both functions are modal, meaning they pause the script execution until the user
interacts with the dialog box.
30. What is the purpose of the prompt() function, and how is it used?
The prompt() function is used to display a message box asking the user for input. It takes the
user's response and stores it in a variable for further processing. For example, developers can
use prompt() to collect a user's name and display a personalized greeting based on their input.
31. Why is JavaScript considered a client-side language, and what are its advantages?
JavaScript is considered a client-side language because it executes directly in the user's browser
without requiring server interaction. This reduces server load and improves the responsiveness
of web applications. Additionally, its ability to manipulate webpage elements dynamically
enhances the overall user experience.
32. What is meant by 'initialization' of a variable, and why is it considered good
practice to initialize variables upon declaration?
Initialization refers to the first assignment of a value to a variable. It is good practice to
initialize variables as it helps avoid undefined or unexpected values, which can lead to
errors in the program. Declaring and initializing a variable together also makes the code
cleaner and reduces the chances of forgetting to assign a value later.
33. What does the modulus (%) operator do in JavaScript?
The modulus (%) operator in JavaScript returns the remainder after dividing one number by
another. For example, if reward is divided by 10 using the modulus operator, it would yield the
remainder of that division, which can be useful in various calculations.
37. How does a 'for loop' work, and what are its main components?
A 'for loop' operates with three main components: initialization, a terminating condition,
and a step size. The index is first initialized, then the loop continues running as long as
the condition is true, and the index is incremented by the step size after each iteration.
This process repeats until the condition is no longer met.
38. What is a nested loop, and when is it used?
A nested loop occurs when one loop is placed inside another. It is used for handling
multiple iterative tasks that are related. In a nested loop, the outer loop runs and each time
it iterates, the inner loop completes its entire cycle, making it useful for tasks involving
multiple dimensions, like processing rows and columns in a table.
39. What is an array, and why is it useful in programming?
An array is a data type that can store multiple values of the same type in a single variable. It is
useful because it allows us to handle large sets of related data efficiently, without needing to
declare numerous separate variables. Each value in an array can be accessed by its index, which
starts at 0.
The Document Object Model (DOM) in HTML is a standard that defines how the
structure and content of an HTML document can be interpreted, manipulated, and
accessed across various operating systems. The DOM organizes HTML files as a DOM-
tree, where each element, attribute, and even comment are treated as nodes within a
hierarchical structure. In this tree, each HTML component—such as tags, scripts, and text
content—is represented as an object or node.
The DOM allows elements within an HTML document to be accessed and manipulated
using their unique element IDs. For instance, the function getElementById() is used to
locate and retrieve an element by its ID. If the element is found, its object is returned;
otherwise, a null value is given. This approach enables web developers to dynamically
Chapter 3: Programming Fundamentals Grade 9
update and control web page content, such as changing text within an element using the
innerHTML property, which retrieves and updates element values.
a) <!DOCTYPE html>: This declaration specifies the HTML version used in the document
(typically HTML5) and helps browsers understand how to render the page.
b) <html> Tag: This is the root element that wraps all the content in the HTML document.
c) <head> Tag: Contains metadata (information about the page), links to stylesheets, scripts,
and other resources.
o <title>: Sets the page title displayed in the browser’s title bar or tab.
o <meta>: Provides metadata, such as character encoding and viewport settings for
responsive design.
o <link>: Links external resources, like stylesheets.
o <style> and <script>: Optionally include CSS or JavaScript directly within the
HTML document.
d) <body> Tag: Contains the visible content of the webpage, such as text, images, links, and
other multimedia.
o This is where elements like <header>, <nav>, <section>, <article>, <footer>,
<div>, and <p> (paragraphs) are structured to create the page layout and display
content.
html
Copy code
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>My Web Page</title>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<header>
<h1>Welcome to My Website</h1>
</header>
<section>
<p>This is a paragraph in the main content area.</p>
</section>
<footer>
<p>© 2024 My Website</p>
</footer>
</body>
</html>
Chapter 3: Programming Fundamentals Grade 9
CSS (Cascading Style Sheets) is a styling language used to define the visual appearance and
layout of HTML elements on a webpage. CSS allows developers to separate content from design,
enabling them to easily modify the look and feel of a website without altering the underlying
HTML structure. CSS can control colors, fonts, spacing, and positioning, making webpages
more visually appealing and user-friendly.
1. Internal Stylesheet
o Internal styles are defined within the <style> tag inside the <head> section of an
HTML document.
o This method is ideal when styling is unique to a single page and won’t be reused
elsewhere.
o Example:
html
Copy code
<head>
<style>
body {
background-color: lightblue;
}
h1 {
color: navy;
text-align: center;
}
</style>
</head>
2. Inline Stylesheet
o Inline styles are added directly within HTML elements using the style attribute.
o This method is typically used to apply unique styling to specific elements but is
less maintainable and recommended only for minimal styling.
o Example:
html
Copy code
<h1 style="color: navy; text-align: center;">Welcome to My
Website</h1>
3. External Stylesheet
o An external stylesheet is a separate CSS file linked to an HTML document via the
<link> tag in the <head> section.
o External stylesheets are ideal for applying a consistent style across multiple pages,
making updates easier and more efficient.
o Example:
Chapter 3: Programming Fundamentals Grade 9
html
Copy code
<head>
<link rel="stylesheet" href="styles.css">
</head>
css
Copy code
body {
background-color: lightblue;
}
h1 {
color: navy;
text-align: center;
}
4. Next
Chapter 3 MCQs
o a) <link>
o b) <a>
o c) <href>
o d) <url>
Answer: b) <a>
o a) src
o b) href
o c) link
o d) img
Answer: a) src
o d) To set hyperlinks
Answer: b) To define the page title in the browser tab
o a) <ul>
o b) <ol>
o c) <list>
o d) <li>
Answer: b) <ol>
Chapter 3 MCQs
CSS MCQs
o a) bgColor
o b) color
o c) background-color
o d) background
Answer: c) background-color
o a) .header
o b) header
o c) #header
o d) *header
Answer: c) #header
o a) font-style
o b) font-size
o c) text-size
o d) text-style
Answer: b) font-size
o d) To center text
Answer: b) To add space around elements
JavaScript MCQs
o a) Number
o b) String
o c) Boolean
o a) *
o b) =
o c) :
o d) %
Answer: b) =
o a) var
o b) let
o c) const
o a) 4
o b) 22
o c) NaN
o d) Syntax Error
Answer: b) 22
o a) display()
Chapter 3 MCQs
o b) console()
o c) alert()
o d) console.log()
Answer: d) console.log()
o a) func
o b) function
o c) method
o d) create
Answer: b) function
o a) &&
o b) %
o c) ===
o d) !=
Answer: b) %
o a) 2
o b) 0
o c) 1
o d) 5
Answer: c) 1
o a) * Comment *
o b) // Comment
o c) # Comment
20. Which JavaScript function displays a message and a textbox to take input from the user?
o a) alert()
o b) confirm()
o c) prompt()
o d) console.log()
Answer: c) prompt()
o a) for
o b) while
o c) do...while
o d) foreach
Answer: c) do...while
o a) 1
o b) -1
o c) 0
o d) None
Answer: c) 0
o a) push()
o b) pop()
o c) add()
o d) append()
Answer: a) push()
24. Which of the following loops can be used to iterate through an array?
o a) for
o b) foreach
o c) while
Chapter 3 MCQs
A website is a collection of static web pages, typically used to provide information. It's
primarily designed for information consumption.
A web application is a dynamic application that interacts with the user and performs
specific tasks, often requiring a server-side component. It's designed for user interaction
and data processing.
2. What is the href attribute, and how is it used?
The href attribute stands for "Hypertext Reference." It's used within anchor tags ( <a>)
to specify the link's destination URL. Here's an example:
HTML
<a href="https://www.example.com">Visit Example Website</a>
You can use the following target attributes within the a tag to control how a linked page
is opened:
_blank: Opens the link in a new tab or window.
4. What are the common text tags used in HTML, and what are their purposes?
importance.
<p>: Paragraph tag, used to define a paragraph.
JavaScript
document.getElementById("myButton").addEventListener("click", function() {
alert("Button clicked!");
});
External CSS is a separate e file with a .css extension that contains all the styles
for a website. It's linked to the HTML document using the <link> tag.
External CSS is generally used for:
The Document Object Model (DOM) is a programming interface for HTML, XML, and
other structured documents. It represents the document as a tree-like structure of
nodes, where each node represents a part of the document.
html
head
title
body
h1
p
JavaScript can interact with the DOM to manipulate the structure, style, and content of a
webpage. For instance, you can change the text of an element, add or remove
elements, or modify the style of elements.
HTML provides six levels of headings, from <h1> to <h6>. The level of importance
decreases as the number increases. Here's a basic example:
HTML
<h1>Main Heading</h1>
<h2>Subheading 1</h2>
<h3>Subheading 2</h3>
<h4>Subheading 3</h4>
<h5>Subheading 4</h5>
<h6>Subheading 5</h6>
To load a background image on a webpage, you can use CSS. Here's how:
4. What are the different methods to incorporate CSS code in an HTML webpage?
There are three main ways to incorporate CSS into an HTML document:
1. Inline CSS:
HTML
<p style="color: blue; font-size: 20px;">This is a paragraph.</p>
2. Internal CSS:
HTML
<head>
<style>
p {
color: red;
}
</style>
</head>
HTML
<style>
table, th, td {
border: 1px solid black;
border-collapse: collapse;
}
th, td {
padding: 15px;
text-align: left;
}
th {
background-color: #dddddd;
}
</style>
<table>
<tr>
<th>Company</th>
<th>Contact</th>
<th>Country</th>
</tr>
<tr>
<td>Alfreds Futterkiste</td>
<td>Maria Anders</td>
<td>Germany</td>
</tr>
<tr>
<td>Centro comercial Moctezuma</td>
<td>Francisco Chang</td>
<td>Mexico</td>
</tr>
</table>
JavaScript can add dynamic behavior to webpages. Here are some examples:
Dynamic content:
JavaScript
document.getElementById("demo").innerHTML = "Hello JavaScript!";
Event handling:
JavaScript
document.getElementById("myButton").addEventListener("click",
function() {
alert("Button clicked!");
});
Form validation:
function validateForm() { let x = document.forms["myForm"]["fname"].value; if (x == "")
{ alert("Name must be filled out"); return false; } }
```html
<marquee>This is scrolling text.</marquee>
8. How can we add a video clip to a website that starts playing as the page loads?
HTML
<video width="320" height="240" autoplay muted>
<source src="movie.mp4" type="video/mp4">
Your browser does not support the video tag.
</video>
9. How can we compile the results of an exam into a tabular form and display it on
a webpage?
Programming Fundamentals
Design a webpage for Annual Function of your school.
Provide with:
Schedule of Events
List of Invited Guest Speakers
Major awards that will be distributed by Chief Guest.
Add some relevant text paragraphs and photographs for each point, along with
an
introductory paragraph.
Solution
<section class="schedule">
<h2>Schedule of Events</h2>
<ul>
<li>6:00 PM - 6:30 PM: Registration and Welcome Drink</li>
<li>6:30 PM - 7:00 PM: Inaugural Ceremony and Welcome Address
by the Principal</li>
<li>7:00 PM - 8:30 PM: Cultural Performances: A mesmerizing
blend of dance, music, and drama</li>
<li>8:30 PM - 9:00 PM: Guest Speaker Session: Inspiring words
from renowned personalities</li>
<li>9:00 PM - 9:30 PM: Award Ceremony: Honoring academic
excellence and extracurricular achievements</li>
<li>9:30 PM - 10:00 PM: Dinner and Networking</li>
</ul>
</section>
<section class="guests">
<h2>Invited Guest Speakers</h2>
<ul>
<li>
<h3>[Guest Speaker 1 Name]</h3>
[Brief bio about the guest speaker, their achievements,
and their contribution to the field]
</li>
<li>
<h3>[Guest Speaker 2 Name]</h3>
[Brief bio about the guest speaker, their achievements,
and their contribution to the field]
</li>
</ul>
</section>
<section class="awards">
<h2>Major Awards</h2>
<p>The Chief Guest will present the following prestigious
awards:</p>
<ul>
<li>Academic Excellence Awards</li>
<li>Sports Excellence Awards</li>
<li>Cultural Excellence Awards</li>
<li>Special Achievement Awards</li>
</ul>
<img src="annual_function_image.jpg" alt="Annual Function Image">
</section>
<footer>
<p>Join us for an unforgettable evening of celebration and
inspiration.</p>
<p>RSVP by [Date]</p>
</footer>
</body>
</html>
Note:
CSS File (style.css): You can create a separate CSS file to style your webpage.
Use CSS to control the layout, colors, fonts, and overall appearance of your
website.
Image: Replace annual_function_image.jpg with the actual path to your image
file.
Content: Replace the placeholder text with your specific information, such as
guest speaker names, bios, and award details.
Additional Features: You can enhance your webpage by adding more sections,
such as a countdown timer, a registration form, or a map to the venue.
By customising this basic structure and adding your own creative touches, you can
create a visually appealing and informative webpage for your Annual Function.
Project 2
Create a webpage about you and your hobbies (like stamp collecting, pets, etc.)
The webpage initially should highlight about your family background, your
personal
achievements and activities. Later, provide details about your every hobby for
creating awareness and motivation for others.
You may add some related links for others who want to start and opt for the same
hobbies.
Solution
Here's a basic HTML structure for a personal webpage highlighting your family
background, achievements, and hobbies:
HTML
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>About Me</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<header>
<h1>About Me</h1>
<img src="your_photo.jpg" alt="Your Photo">
</header>
<section class="personal-info">
<h2>Personal Information</h2>
<p><strong>Name:</strong> [Your Name]</p>
<p><strong>Age:</strong> [Your Age]</p>
<p><strong>Location:</strong> [Your Location]</p>
<p><strong>Hobbies:</strong> [List of your hobbies]</p>
</section>
<section class="family-background">
<h2>Family Background</h2>
<p>[Brief description of your family, their professions, and your
upbringing]</p>
</section>
<section class="achievements">
<h2>Achievements</h2>
<ul>
<li>[Achievement 1]</li>
<li>[Achievement 2]</li>
<li>[Achievement 3]</li>
</ul>
</section>
<section class="hobbies">
<h2>Hobbies</h2>
<h3>Stamp Collecting</h3>
<p>[Detailed description of your interest in stamp collecting,
including the history, different types of stamps, and your collection]</p>
<p><a href="https://www.stamps.com/" target="_blank">Start Your
Stamp Collection</a></p>
<h3>Pet Care</h3>
<p>[Detailed description of your love for pets, your pet(s), and
your experiences with pet care]</p>
<p><a href="https://www.aspca.org/" target="_blank">Learn More
About Animal Welfare</a></p>
</section>
<footer>
<p>© [Your Name] [Year]</p>
</footer>
</body>
</html>
Remember to:
1. Customize the HTML: Replace the placeholder text with your specific
information.
2. Add a CSS file: Use CSS to style your webpage, making it visually appealing.
3. Add more sections: Create additional sections for other hobbies, such as
reading, writing, gardening, or painting.
4. Include images: Add images to enhance your webpage's visual appeal.
5. Consider using a CMS: If you want to easily update your website, consider using
a Content Management System (CMS) like WordPress or Wix.
By following these guidelines, you can create a personalized and informative webpage
that showcases your unique identity and interests.
Project 3
Create a webpage about you and your hobbies (like stamp collecting, pets, etc.)
The webpage initially should highlight about your family background, your
personal
achievements and activities. Later, provide details about your every hobby for
creating awareness and motivation for others.
You may add some related links for others who want to start and opt for the same
hobbies.
Solution
Here's a basic HTML structure and CSS styling for a home-made food website:
HTML Structure:
HTML
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Home-Made Delights</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<header>
<h1>Home-Made Delights</h1>
<p>Taste the Love, Home-Cooked</p>
</header>
<section class="hero">
<img src="hero_image.jpg" alt="Hero Image">
<p>Organic, Home-Made Goodness</p>
</section>
<section class="menu">
<h2>Our Menu</h2>
<div class="menu-item">
<h3>Dish 1</h3>
<img src="dish1_image.jpg" alt="Dish 1 Image">
<p>Ingredients: [List of ingredients]</p>
<p>Price: [Price]</p>
<p>Serves: [Number of servings]</p>
</div>
</section>
<section class="contact">
<h2>Contact Us</h2>
<p><strong>Phone:</strong> [Phone Number]</p>
<p><strong>Email:</strong> [Email Address]</p>
<p><strong>Address:</strong> [Address]</p>
<p><strong>Delivery Options:</strong> [Delivery options, e.g., self-
pickup, delivery within a certain radius]</p>
</section>
<footer>
<p>© 2023 Home-Made Delights</p>
</footer>
</body>
</html>
CSS
body {
font-family: Arial, sans-serif;
margin: 0;
padding: 0;
background-image: url('logo_background.jpg'); /* Replace with your logo
image */
background-size: cover;
background-repeat: no-repeat;
}
header {
text-align: center;
padding: 20px;
background-color: rgba(0, 0, 0, 0.7);
color: white;
}
.hero {
text-align: center;
padding: 50px;
}
.menu {
text-align: center;
padding: 50px;
}
.menu-item {
border: 1px solid #ccc;
padding: 20px;
margin: 20px;
}
footer {
text-align: center;
padding: 20px;
background-color: rgba(0, 0, 0, 0.7);
color: white;
}
Use code with caution.
Logo Design:
You can use a graphic design tool like Adobe Illustrator or Canva to create a logo that reflects
the home-made, organic nature of your food. Consider using a simple, clean design with natural
colors and fonts.
Key Points: