Federal Board Class 10th Chemistry (New Book) – Chapter 1: History of Chemistry Exercise Solved

MCQS


i. What is the principle of conservation of mass?

Options:
a) Mass is created during a chemical reaction
b) Mass is destroyed during a chemical reaction
c) Mass remains constant during a chemical reaction
d) Mass can be converted into energy

Answer:
c) Mass remains constant during a chemical reaction

Explanation:
The principle of conservation of mass states that mass is neither created nor destroyed in a chemical reaction; it is only rearranged. This was first formulated by Antoine Lavoisier.

Tips/Tricks:

  • Remember the phrase: “Matter cannot be created or destroyed.”
  • Eliminate options suggesting mass is created/destroyed (a, b). Option (d) refers to mass-energy equivalence (Einstein’s theory), which is not the conservation of mass.

ii. What does the peer review process ensure in scientific research?

Options:
a) Faster publication
b) Accuracy and validity of findings
c) Higher funding
d) Reduced experimentation

Answer:
b) Accuracy and validity of findings

Explanation:
Peer review involves evaluation by experts in the field to ensure the research is credible, methodologically sound, and free of errors before publication.

Tips/Tricks:

  • Focus on the purpose of peer review: quality control. Options (a), (c), and (d) are unrelated to its primary goal.

iii. Which of the following was an 18th-century chemical paradigm?

Options:
a) Atomic theory
b) Phlogiston theory
c) Quantum mechanics
d) Periodic table

Answer:
b) Phlogiston theory

Explanation:
The phlogiston theory (17th–18th century) proposed that a fire-like element (“phlogiston”) was released during combustion. It was later disproven by Lavoisier.

Tips/Tricks:

  • Note the time frame: “18th century.” Atomic theory (a) and the periodic table (d) emerged later. Quantum mechanics (c) is 20th-century.

iv. What does the periodic table of elements organize?

Options:
a) Elements by alphabetical order
b) Elements by their properties and atomic number
c) Elements by colour
d) Elements by discovery date

Answer:
b) Elements by their properties and atomic number

Explanation:
The periodic table arranges elements in order of increasing atomic number and groups them by similar chemical properties.

Tips/Tricks:

  • Recall that atomic number (proton count) is the primary organizing factor.

v. What does a 95% confidence level mean in scientific reporting?

Options:
a) Results are 95% accurate
b) There is a 5% chance the results are incorrect
c) 95% of scientists agree
d) The experiment is repeated 95 times

Answer:
b) There is a 5% chance the results are incorrect

Explanation:
A 95% confidence level means there is a 5% probability that the observed results occurred by random chance.

Tips/Tricks:

  • “Confidence level” relates to statistical probability, not accuracy (a) or consensus (c).

vi. Which model of the atom includes a central nucleus?

Options:
a) Plum-pudding model
b) Rutherford model
c) Bohr model
d) Quantum mechanical model

Answer:
b) Rutherford model

Explanation:
Rutherford’s gold foil experiment (1911) revealed the atom’s dense nucleus, replacing the plum-pudding model (a).

Tips/Tricks:

  • Bohr (c) and quantum models (d) came later and built on Rutherford’s nucleus discovery.

vii. What does repeatability in scientific experiments refer to?

Options:
a) Different results under the same conditions
b) Same results under the same conditions
c) Different methods
d) Multiple publications

Answer:
b) Same results under the same conditions

Explanation:
Repeatability means the same team can replicate results using identical methods and conditions.

Tips/Tricks:

  • “Repeat” = same conditions. “Reproducibility” (next question) involves different conditions.

viii. What is reproducibility in scientific experiments?

Options:
a) Different results under the same conditions
b) Same results using different methods
c) Results not verified
d) Repetition by the same scientist

Answer:
b) Same results using different methods

Explanation:
Reproducibility means independent teams can achieve similar results with different methods or setups.

Tips/Tricks:

  • Contrast with repeatability: reproducibility is broader (different labs/methods).

ix. What paradigm replaced the phlogiston theory?

Options:
a) Atomic theory
b) Theory of combustion
c) Quantum mechanics
d) Periodic table

Answer:
b) Theory of combustion

Explanation:
Lavoisier’s theory of combustion (involving oxygen) replaced the phlogiston theory in the late 18th century.

Tips/Tricks:

  • Link phlogiston to combustion. Atomic theory (a) and periodic table (d) are unrelated.

x. Which property does the periodic table help to predict?

Options:
a) Colour of elements
b) Properties of elements
c) Weight of elements
d) Discovery date of elements

Answer:
b) Properties of elements

Explanation:
The periodic table’s arrangement reveals trends in chemical properties (e.g., reactivity, electronegativity).

Tips/Tricks:

  • Focus on “properties,” as other options (a, c, d) are not primary purposes of the table.

Short Questions:

i. Explain the principle of conservation of mass in chemical reactions.

Answer:
The principle of conservation of mass states that mass is neither created nor destroyed in a chemical reaction. The total mass of the reactants (substances before the reaction) is always equal to the total mass of the products (substances after the reaction). This law was formulated by Antoine Lavoisier, who demonstrated it through experiments.

Example:
When magnesium burns in oxygen, the mass of magnesium oxide formed equals the combined mass of magnesium and oxygen used.

Key Points:

  1. Mass remains constant.
  2. Atoms are rearranged, not destroyed.
  3. Lavoisier proved this through experiments.

ii. What is the role of empirical evidence in scientific research?

Answer:
Empirical evidence refers to data collected through observation and experimentation rather than just theories. It is crucial in science because:

  1. Supports or disproves hypotheses – Scientists rely on experiments to verify ideas.
  2. Ensures objectivity – Results must be measurable and repeatable.
  3. Forms the basis of scientific laws – Repeated observations lead to established facts (e.g., conservation of mass).

Example:
Lavoisier’s experiments on combustion provided empirical evidence against the phlogiston theory.


iii. Describe the peer review process and its importance in science.

Answer:
The peer review process involves experts evaluating a scientific study before it is published.

Steps:

  1. A scientist submits research to a journal.
  2. Experts in the field review it for accuracy, validity, and methodology.
  3. If approved, it is published; if not, corrections are suggested.

Importance:

  • Ensures high-quality, reliable research.
  • Prevents false or misleading claims.
  • Maintains trust in scientific knowledge.

iv. How did the phlogiston theory explain combustion?

Answer:
The phlogiston theory (17th–18th century) proposed that:

  1. A fire-like substance called phlogiston was present in combustible materials.
  2. During burning, phlogiston was released into the air.
  3. Materials stopped burning when all phlogiston was gone.

Limitation:

  • It failed to explain why metals gained mass when burned (later explained by oxygen theory).

v. What is the significance of Rutherford’s model of the atom?

Answer:
Rutherford’s nuclear model (1911) was significant because:

  1. It disproved the plum-pudding model (which said atoms were uniform).
  2. It introduced the concept of a dense, positively charged nucleus.
  3. It showed that most of the atom is empty space with electrons orbiting.

Experiment:
Gold foil experiment—alpha particles were deflected, proving the nucleus existed.


vi. How does the periodic table organize elements?

Answer:
The periodic table organizes elements by:

  1. Atomic number (proton count) – Elements are arranged in increasing order.
  2. Groups (columns) – Elements with similar properties (e.g., alkali metals in Group 1).
  3. Periods (rows) – Shows trends like increasing reactivity.

Example:

  • Group 17 (Halogens): Highly reactive nonmetals (e.g., chlorine, fluorine).
  • Period 3: Contains sodium (Na), magnesium (Mg), etc.

vii. Define scientific paradigm with an example.

Answer:
A scientific paradigm is a widely accepted framework that guides research.

Example:

  • Phlogiston theory (old paradigm for combustion).
  • Oxygen theory (new paradigm by Lavoisier).

Key Idea:
When new evidence challenges a paradigm, a scientific revolution occurs (e.g., shift from phlogiston to oxygen).


viii. What does a confidence level in scientific research indicate?

Answer:
A confidence level (e.g., 95%) indicates:

  1. The probability that results are not due to random chance.
  2. A 95% confidence level means there is a 5% chance of error.
  3. It helps scientists assess reliability (e.g., in drug trials).

Example:
If a study says “95% confidence,” it means the conclusion is likely correct 19 out of 20 times.


ix. Differentiate between repeatability and reproducibility in experiments.

Answer:

RepeatabilityReproducibility
Same results when the same scientist repeats the experiment under identical conditions.Same results when different scientists repeat the experiment using different methods/labs.
Example: A chemist replicates their own experiment.Example: Multiple labs confirm a discovery independently.

Importance:

  • Repeatability ensures consistency.
  • Reproducibility validates broader reliability.

x. Why is skepticism important in the scientific community?

Answer:
Skepticism is crucial because:

  1. It prevents blind acceptance of claims without evidence.
  2. Encourages testing and verification (e.g., debunking phlogiston theory).
  3. Leads to better theories (e.g., oxygen replacing phlogiston).

Example:
Scientists questioned the phlogiston theory until Lavoisier provided better evidence for oxygen.


Long Questions:

Long Answer Questions (Detailed Solutions)


i. Transition from Phlogiston Theory to Oxygen Theory of Combustion

1. Phlogiston Theory (17th–18th Century)

  • Explanation:
  • Proposed by Georg Ernst Stahl.
  • Suggested that combustible materials contained “phlogiston” (a fire-like substance).
  • During burning, phlogiston was released into the air.
  • Limitations:
  • Could not explain why metals gained mass after burning (e.g., magnesium oxide).
  • Contradicted empirical evidence.

2. Oxygen Theory (Late 18th Century)

  • Lavoisier’s Contributions:
  • Demonstrated that combustion requires oxygen (not phlogiston).
  • Showed that metals combined with oxygen from the air, increasing their mass.
  • Introduced the law of conservation of mass.
  • Impact on Chemistry:
  • Disproved phlogiston theory, leading to modern chemical nomenclature.
  • Established quantitative methods in chemistry (measuring reactants/products).

3. Key Example:

  • Experiment: Heating mercury oxide produced oxygen, proving it was part of combustion.

Exam Tip: Focus on Lavoisier’s experiments and how they debunked phlogiston.


ii. Development of Atomic Models

1. Plum-Pudding Model (J.J. Thomson, 1897)

  • Description:
  • Atom as a “pudding” of positive charge with electrons embedded (like raisins).
  • Limitation: Could not explain atomic stability.

2. Rutherford’s Nuclear Model (1911)

  • Gold Foil Experiment:
  • Alpha particles deflected by a dense nucleus.
  • Proved atoms are mostly empty space.
  • Key Change: Introduced the central nucleus (protons + neutrons).

3. Bohr Model (1913)

  • Improvements:
  • Electrons orbit in fixed energy levels (shells).
  • Explained atomic spectra (e.g., hydrogen’s emission lines).

4. Quantum Mechanical Model (Modern Model)

  • Key Features:
  • Electrons exist in probability clouds (orbitals).
  • Uses quantum numbers to describe electron location.

Exam Tip: Compare each model’s strengths/weaknesses and experimental evidence.


iii. Periodic Table as a Paradigm in Chemistry

1. Organization Principles:

  • Atomic Number: Elements arranged by proton count.
  • Groups (Columns): Similar chemical properties (e.g., Group 1 = Alkali Metals).
  • Periods (Rows): Trends in reactivity and atomic size.

2. Predictive Power:

  • Mendeleev’s Predictions: Left gaps for undiscovered elements (e.g., gallium, germanium).
  • Modern Applications:
  • Predicts reactivity (e.g., fluorine = most reactive nonmetal).
  • Guides synthesis of new elements (e.g., synthetic elements like Tennessine).

3. Impact on Research:

  • Unified chemistry by classifying elements systematically.
  • Enabled discoveries like noble gases (Group 18).

Exam Tip: Highlight Mendeleev’s contributions and modern applications.


iv. Importance of Repeatability and Reproducibility

1. Definitions:

  • Repeatability: Same results under identical conditions (same lab).
  • Reproducibility: Same results under different conditions (other labs).

2. Role in Scientific Integrity:

  • Prevents Fraud: Ensures data is not fabricated (e.g., cold fusion controversy).
  • Validates Theories:
  • Example: Lavoisier’s experiments were repeated to confirm oxygen theory.
  • Failed Reproducibility: Phlogiston theory collapsed when others couldn’t verify it.

3. Case Study:

  • Millikan’s Oil Drop Experiment: Repeated globally to confirm electron charge.

Exam Tip: Contrast repeatability (same team) vs. reproducibility (independent teams).


v. Confidence Levels and Uncertainty in Chemistry Experiments

1. Definitions:

  • Confidence Level (e.g., 95%): Probability that results are not due to chance.
  • Uncertainty: Margin of error in measurements (e.g., ±0.01g).

2. Expression in Research:

  • Statistical Tools:
  • Standard deviation: Measures data spread.
  • p-value: Likelihood of observed results occurring randomly.
  • Example:
  • A drug trial with “95% confidence” means results are reliable 19/20 times.

3. Practical Example:

  • Titration Experiments:
  • Report average volume with ± uncertainty (e.g., 24.30 ± 0.05 mL).
  • Repeats reduce uncertainty.

Exam Tip: Link confidence levels to real chemistry experiments (e.g., titration).


Chapter 8: Web Development with HTML, CSS, and JavaScript – Solved Exercise

Solved Multiple Choice Questions with Explanations & Tips

1. Which of the following tag is not a correct HTML tag?

  • (a) <div>
  • (b) <span>
  • (c) <head>
  • (d) <footer>
    Answer: None of these (All are correct HTML tags)

🔹 Explanation:
All four options (<div>, <span>, <head>, <footer>) are valid HTML tags. <div> and <span> are used for structuring and styling, <head> contains metadata, and <footer> represents the footer section of a webpage.

💡 Tip: Always check the latest HTML specifications for valid tags. You can refer to MDN Web Docs for updated information.


2. What does CSS stand for?

  • (a) Cascading Style Sheets
  • (b) Computer Style Sheets
  • (c) Creative Style Sheets
  • (d) Colorful Style Sheets
    Answer: (a) Cascading Style Sheets

🔹 Explanation:
CSS stands for Cascading Style Sheets, which is used to define the presentation of HTML documents, including layout, colors, and fonts.

💡 Tip: The word “Cascading” refers to how styles are applied in a hierarchy, from external stylesheets to inline styles.


3. Which of the following tag is used to create a hyperlink in HTML?

  • (a) <link>
  • (b) <a>
  • (c) <href>
  • (d) <nav>
    Answer: (b) <a>

🔹 Explanation:
The <a> (anchor) tag is used to create hyperlinks in HTML. The href attribute inside the <a> tag specifies the link’s destination.

💡 Tip: Use the target="_blank" attribute to open links in a new tab, like this: <a href="https://example.com" target="_blank">Click Here</a>.


4. Which property is used to change the background color in CSS?

  • (a) color
  • (b) background-color
  • (c) bgcolor
  • (d) background
    Answer: (b) background-color

🔹 Explanation:
The background-color property is used to set the background color of an element in CSS.

💡 Tip: Use color for text color and background-color for background color. Example:

body {
  background-color: lightblue;
}

5. Which HTML attribute is used to define inline styles?

  • (a) class
  • (b) style
  • (c) font
  • (d) styles
    Answer: (b) style

🔹 Explanation:
The style attribute allows inline CSS styling directly in an HTML tag.

💡 Tip: Avoid excessive use of inline styles; instead, use external CSS for better maintainability.
Example:

<p style="color: red;">This is a red text.</p>

6. Which of the following is the correct syntax for a CSS rule?

  • (a) selector {property: value;}
  • (b) selector: {property=value;}
  • (c) selector {property=value}
  • (d) selector: {property: value;}
    Answer: (a) selector {property: value;}

🔹 Explanation:
CSS rules follow the syntax:

selector {
  property: value;
}

💡 Tip: Always end CSS statements with a semicolon (;) to avoid errors.


7. In JavaScript, which markup is used for comments?

  • (a) /* */
  • (b) //
  • (c) <–
  • (d) /* */
    Answer: Both (a) and (b)

🔹 Explanation:

  • Single-line comments: // This is a comment
  • Multi-line comments: /* This is a multi-line comment */

💡 Tip: Use comments to explain code but avoid excessive commenting in obvious cases.


8. How do you include JavaScript in an HTML document?

  • (a) <script src="script.js"></script>
  • (b) <java src="script.js"></java>
  • (c) <js src="script.js"></js>
  • (d) <code src="script.js"></code>
    Answer: (a) <script src="script.js"></script>

🔹 Explanation:
JavaScript is included in HTML using the <script> tag, either inline or by linking an external file.

💡 Tip: Place <script> before the closing </body> tag to improve page load speed.


9. Which HTML tag is used to create an unordered list?

  • (a) <ol>
  • (b) <ul>
  • (c) <li>
  • (d) <list>
    Answer: (b) <ul>

🔹 Explanation:
The <ul> tag is used for unordered (bulleted) lists, whereas <ol> is for ordered (numbered) lists.

💡 Tip: Use <li> inside <ul> or <ol> to define list items.
Example:

<ul>
  <li>Item 1</li>
  <li>Item 2</li>
</ul>

10. Which tag is used to display a horizontal line in HTML?

  • (a) <br>
  • (b) <hr>
  • (c) <line>
  • (d) <hline>
    Answer: (b) <hr>

🔹 Explanation:
The <hr> (horizontal rule) tag creates a horizontal line in HTML, typically used to separate content.

💡 Tip: Customize the appearance using CSS, e.g.:

hr {
  border: 2px solid black;
}

Solved Short Questions (Simple & Easy Language)

1. What is the purpose of the <head> tag in HTML?

The <head> tag contains important information about the web page that is not visible to users. It includes:

  • The title of the page (<title>)
  • Links to CSS files (<link>)
  • Meta information (<meta>)
  • JavaScript files (<script>)

2. Explain the difference between an ordered list and an unordered list in HTML.

  • Ordered List (<ol>): It shows items in a numbered format (1, 2, 3…).
  • Unordered List (<ul>): It shows items with bullet points (●, ■, ○).

Example:

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

<ul>
  <li>First Item</li>
  <li>Second Item</li>
</ul>

3. How do you add a comment in CSS?

In CSS, we use /* */ for comments.
Example:

/* This is a comment */
p {
  color: blue; /* This line changes text color to blue */
}

Comments are ignored by the browser and are used to explain code.


4. What are the different ways to apply CSS to an HTML document?

There are three ways to apply CSS:

  1. Inline CSS – Written inside the HTML tag using the style attribute. <p style="color: red;">Hello</p>
  2. Internal CSS – Written inside the <style> tag in the <head> section. <style> p { color: blue; } </style>
  3. External CSS – Written in a separate .css file and linked using <link>. <link rel="stylesheet" href="style.css">

5. How can you include JavaScript in an HTML file?

We can include JavaScript in two ways:

  1. Inline JavaScript: Inside the <script> tag in the HTML file. <script> alert("Hello World!"); </script>
  2. External JavaScript: Linking a separate JavaScript file (.js). <script src="script.js"></script>

6. Describe the syntax for creating a hyperlink in HTML.

A hyperlink is created using the <a> tag with the href attribute.
Example:

<a href="https://www.google.com">Visit Google</a>

This will create a clickable link that opens Google.


7. What is the function of the <div> tag in HTML?

The <div> tag is used to group other HTML elements together. It helps in styling and layout design.

Example:

<div style="background-color: lightgray; padding: 10px;">
  <p>This is inside a div.</p>
</div>

It is like a container for other elements.


8. How do you link an external CSS file to an HTML document?

We use the <link> tag inside the <head> section.

Example:

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

This connects an external style.css file to the HTML page.


9. What is the use of the <table> tag in HTML?

The <table> tag is used to create tables to display data in rows and columns.

Example:

<table border="1">
  <tr>
    <th>Name</th>
    <th>Age</th>
  </tr>
  <tr>
    <td>Ali</td>
    <td>15</td>
  </tr>
</table>

This will create a simple table with a border.


10. Explain the box model in CSS.

The CSS box model explains how elements are displayed on a webpage. It includes:

  1. Content – The main text or image inside the box.
  2. Padding – Space inside the box, around the content.
  3. Border – The outer edge of the box.
  4. Margin – Space outside the box, separating it from other elements.

Example:

div {
  width: 200px;
  padding: 10px;
  border: 5px solid black;
  margin: 20px;
}

This defines a box with content, padding, border, and margin.


💡 Tip for Students: Keep practicing with small HTML and CSS examples to understand better. 🚀

Solved Long Questions (Simple & Easy for Class 9)


1. Discuss the fundamental differences between HTML, CSS, and JavaScript in the context of web development.

In web development, HTML, CSS, and JavaScript work together to create a complete website. Here’s how they differ:

FeatureHTMLCSSJavaScript
PurposeStructure of a webpageStyling and designMakes the webpage interactive
What it doesDefines headings, paragraphs, images, tables, etc.Changes colors, fonts, layout, and animationsAdds buttons, forms, and real-time interactions
Example<h1>Heading</h1>h1 { color: red; }document.write("Hello!");

🔹 Simple Example:

<!DOCTYPE html>
<html>
<head>
    <style>
        h1 { color: blue; }
    </style>
    <script>
        function showMessage() {
            alert("Hello, this is JavaScript!");
        }
    </script>
</head>
<body>
    <h1>Welcome to Web Development</h1>
    <button onclick="showMessage()">Click Me</button>
</body>
</html>

HTML creates the heading and button.
CSS makes the heading blue.
JavaScript makes the button show an alert when clicked.


2. Explain the process of setting up a development environment for web development.

To start web development, you need some basic software and tools:

1. Text Editor (for writing code)

  • Notepad++ (Simple and easy)
  • VS Code (Popular among developers)

2. Web Browser (for testing webpages)

  • Google Chrome (Best for development)
  • Mozilla Firefox

3. Local Web Server (for testing advanced web pages)

  • XAMPP (For PHP and databases)

4. Steps to Set Up

  1. Install VS Code and a web browser.
  2. Open VS Code and create an index.html file.
  3. Write a basic HTML page and save it.
  4. Open the file in a web browser to see your webpage.

💡 Tip: Always save your file with .html extension before testing.


3. Create a basic HTML page that includes a header, a paragraph, an image, and a hyperlink.

Code for a simple webpage:

<!DOCTYPE html>
<html>
<head>
    <title>My First Webpage</title>
</head>
<body>
    <h1>Welcome to My Website</h1>
    <p>This is my first webpage. I am learning HTML!</p>
    <img src="image.jpg" alt="A beautiful scenery" width="300">
    <br>
    <a href="https://www.google.com">Click here to visit Google</a>
</body>
</html>

💡 Save this as index.html and open it in a browser.


4. How do you style a table using CSS? Create a sample table and apply styles to it.

HTML Table with CSS Styling

<!DOCTYPE html>
<html>
<head>
    <style>
        table {
            width: 50%;
            border-collapse: collapse;
        }
        th, td {
            border: 1px solid black;
            padding: 10px;
            text-align: center;
        }
        th {
            background-color: lightblue;
        }
        tr:nth-child(even) {
            background-color: lightgray;
        }
    </style>
</head>
<body>
    <h2>Student Marks</h2>
    <table>
        <tr>
            <th>Name</th>
            <th>Marks</th>
        </tr>
        <tr>
            <td>Ali</td>
            <td>85</td>
        </tr>
        <tr>
            <td>Sara</td>
            <td>90</td>
        </tr>
    </table>
</body>
</html>

💡 Tip: Use border-collapse: collapse; to remove space between table borders.


5. Describe the different CSS selectors and provide examples of each.

Selector TypeExampleDescription
Element Selectorp { color: red; }Styles all <p> tags.
Class Selector.highlight { color: blue; }Styles elements with class="highlight".
ID Selector#title { font-size: 20px; }Styles an element with id="title".
Group Selectorh1, h2 { text-align: center; }Styles multiple elements together.

Example:

#main {
    color: green;
}
.highlight {
    background-color: yellow;
}

💡 Tip: Use classes when styling multiple elements and IDs for unique elements.


6. Explain the process of creating a responsive web page using CSS.

A responsive webpage adjusts its layout for different screen sizes.

Example using Media Queries:

body {
    font-size: 16px;
}
@media (max-width: 600px) {
    body {
        font-size: 12px;
    }
}

🔹 Explanation:

  • The font size is 16px by default.
  • When the screen width is 600px or smaller, the font size reduces to 12px.

💡 Tip: Use flexbox and grid for better responsive design.


7. Write a JavaScript function that changes the background color of a web page when a button is clicked.

HTML + JavaScript Code:

<!DOCTYPE html>
<html>
<head>
    <script>
        function changeColor() {
            document.body.style.backgroundColor = "lightblue";
        }
    </script>
</head>
<body>
    <button onclick="changeColor()">Click to Change Color</button>
</body>
</html>

🔹 Explanation:

  • The onclick event runs the changeColor() function when the button is clicked.
  • document.body.style.backgroundColor = "lightblue"; changes the background color.

💡 Tip: You can use "random" colors using Math.random().


8. How do you add animations and transitions using CSS?

Example of a simple animation:

@keyframes move {
    from { left: 0px; }
    to { left: 200px; }
}

.box {
    position: relative;
    width: 100px;
    height: 100px;
    background-color: red;
    animation: move 2s linear infinite;
}

Example of a button with transition:

button {
    background-color: blue;
    color: white;
    padding: 10px;
    transition: background-color 0.5s;
}
button:hover {
    background-color: green;
}

🔹 Explanation:

  • Animation moves a box from left to right.
  • Transition smoothly changes button color when hovered.

💡 Tip: Use ease-in-out for smoother effects.


🔥 Conclusion: Learning HTML, CSS, and JavaScript step by step helps in building amazing websites. Keep practicing and experimenting with code! 🚀