class 8 science chapter 12

ch12 part13

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>🧠 Science Quiz – Habitat and Ecosystem</title>
<style>
body {
  font-family: Arial, sans-serif;
  background: linear-gradient(135deg, #a1c4fd, #c2e9fb);
  display: flex;
  justify-content: center;
  align-items: flex-start;
  padding: 30px;
  min-height: 100vh;
}
.quiz-container {
  background: #fff;
  padding: 25px;
  border-radius: 12px;
  box-shadow: 0 4px 10px rgba(0,0,0,0.2);
  width: 90%;
  max-width: 800px;
}
h2 { text-align: center; color: #1e3c72; }
.question { font-weight: bold; margin: 10px 0; }
.options label {
  display: block;
  margin: 8px 0;
  padding: 10px;
  border-radius: 6px;
  border: 1px solid #ccc;
  cursor: pointer;
  transition: 0.3s;
}
.options label:hover { background: #f0f0f0; }
.correct { background-color: #c8f7c5 !important; border-color: #28a745 !important; }
.wrong { background-color: #f8d7da !important; border-color: #dc3545 !important; }
.explanation {
  background: #e9ecef;
  padding: 10px;
  margin-top: 10px;
  border-left: 5px solid #2a5298;
  display: none;
}
.controls { text-align: center; margin-top: 15px; }
button {
  background-color: #2a5298;
  color: white;
  border: none;
  padding: 10px 20px;
  border-radius: 6px;
  cursor: pointer;
  margin: 5px;
}
button:hover { background-color: #1e3c72; }
#scoreboard {
  margin-top: 25px;
  background: #eef3f7;
  padding: 15px;
  border-radius: 8px;
}
#scoreboard h3 { text-align: center; }
ol { padding-left: 20px; }
</style>
</head>

<body>
<div class="quiz-container">

<h2>🧠 Science Quiz – Habitat and Ecosystem</h2>

<div id="nameSection">
  <p><strong>Enter your name to start:</strong></p>
  <input type="text" id="userName" placeholder="Your Name">
  <button onclick="startQuiz()">Start Quiz</button>
</div>

<div id="quizSection" style="display:none;">
  <div id="questionContainer"></div>

  <div class="controls">
    <button onclick="prevQuestion()" id="prevBtn">Previous</button>
    <button onclick="nextQuestion()" id="nextBtn">Next</button>
    <button onclick="submitQuiz()" id="submitBtn" style="display:none;">Submit</button>
  </div>

  <div id="result" style="text-align:center; margin-top:20px;"></div>

  <div id="scoreboard">
    <h3>🏆 Scoreboard</h3>
    <ol id="scoreList"></ol>
  </div>
</div>
</div>

<script>
const questions = [

{
question: "1. Habitat kise kehte hain?",
options: [
"A. Aisi jagah jahan sirf plants grow karte hain",
"B. Aisi jagah jo organism ko live aur grow karne ke liye suitable conditions deti hai",
"C. Aisi jagah jahan water nahi hota",
"D. Aisi jagah jahan koi living organism nahi hota"
],
correct: 1,
explanation: "Habitat ek natural ya suitable place hota hai jahan organism ko food, water, shelter aur survival ke liye zaroori conditions milti hain.<br><br>Example: Pond frog ka habitat ho sakta hai kyunki wahan use water, food aur shelter milte hain."
},

{
question: "2. Inmein se kaunsa abiotic component hai?",
options: [
"A. Grass",
"B. Bacteria",
"C. Soil",
"D. Butterfly"
],
correct: 2,
explanation: "Abiotic components ecosystem ke non-living parts hote hain, jaise air, water, soil aur temperature. Biotic components living organisms hote hain.<br><br>Example: Forest mein trees biotic components hain, jabki soil aur sunlight abiotic components hain."
},

{
question: "3. Ecosystem ka formation kaise hota hai?",
options: [
"A. Sirf animals se",
"B. Sirf plants se",
"C. Biotic aur abiotic components ke interaction se",
"D. Sirf water aur air se"
],
correct: 2,
explanation: "Ecosystem mein living organisms aur non-living environment ek-doosre ke saath interact karte hain.<br><br>Example: Pond mein fish, plants aur microorganisms water, sunlight aur dissolved oxygen ke saath interact karte hain."
},

{
question: "4. Food chain mein producers kaun hote hain?",
options: [
"A. Animals jo plants ko khate hain",
"B. Green plants jo apna food banate hain",
"C. Fungi jo dead matter ko break down karte hain",
"D. Animals jo sirf meat khate hain"
],
correct: 1,
explanation: "Producers photosynthesis ke through sunlight ki energy use karke apna food banate hain. Ye food chain ka starting point hote hain.<br><br>Example: Grass apna food banati hai aur grasshopper ke liye food provide karti hai."
},

{
question: "5. Decomposers ecosystem mein kya kaam karte hain?",
options: [
"A. Dead matter ko break down karke nutrients recycle karte hain",
"B. Sirf living animals ko hunt karte hain",
"C. Sunlight produce karte hain",
"D. Saare plants ko destroy karte hain"
],
correct: 0,
explanation: "Decomposers dead plants aur animals ko simpler substances mein break down karte hain. Is process se nutrients environment mein wapas aate hain.<br><br>Example: Fungi aur bacteria dead leaves ko decompose karke nutrients ko soil mein return karne mein help karte hain."
},

{
question: "6. Food web aur food chain mein kya difference hai?",
options: [
"A. Food chain interconnected feeding relationships ka network hoti hai",
"B. Food web sirf ek organism ko show karta hai",
"C. Food web multiple interconnected food chains ko show karta hai",
"D. Dono ka meaning completely same hai"
],
correct: 2,
explanation: "Food chain ek feeding pathway show karti hai, jabki food web ecosystem mein multiple connected feeding pathways ko show karta hai.<br><br>Example: Grass ko grasshopper aur rabbit dono kha sakte hain. Grasshopper ko frog kha sakta hai, aur frog ko snake. Ye connected pathways food web ka part hain."
},

{
question: "7. Bees aur flowering plants ke beech mutualism ka example kyun milta hai?",
options: [
"A. Bee ko benefit hota hai aur plant ko harm hota hai",
"B. Plant ko benefit hota hai aur bee ko harm hota hai",
"C. Dono ko benefit hota hai",
"D. Kisi ko benefit nahi hota"
],
correct: 2,
explanation: "Mutualism mein dono organisms benefit receive karte hain. Bees flowers se nectar aur pollen leti hain, jabki pollination mein help kar sakti hain.<br><br>Example: Bee flower se nectar collect karti hai aur pollen transfer karke plant ki reproduction mein help karti hai."
},

{
question: "8. Tick aur dog ke relationship ko kya kehte hain?",
options: [
"A. Mutualism",
"B. Commensalism",
"C. Parasitism",
"D. Decomposition"
],
correct: 2,
explanation: "Parasitism mein ek organism benefit leta hai aur doosre organism ko harm hota hai. Tick dog ka blood suck karta hai aur dog ko harm pahuncha sakta hai.<br><br>Example: Dog ke body par tick ka attached rehna parasitism ka example hai."
},

{
question: "9. Ecosystem humans ko kaunsa important benefit provide karta hai?",
options: [
"A. Clean air aur water",
"B. Sirf plastic waste",
"C. Sirf noise pollution",
"D. Natural resources ka complete destruction"
],
correct: 0,
explanation: "Healthy ecosystems food, clean water, medicines, clean air aur climate regulation jaise important benefits provide karte hain. Ye benefits human survival aur well-being ke liye zaroori hain.<br><br>Example: Trees carbon dioxide absorb karte hain aur photosynthesis ke dauraan oxygen release karte hain."
},

{
question: "10. National parks aur wildlife sanctuaries banane ka main purpose kya hai?",
options: [
"A. Deforestation badhana",
"B. Wildlife aur natural habitats ko conserve karna",
"C. Pollution badhana",
"D. Saare predators ko remove karna"
],
correct: 1,
explanation: "National parks aur wildlife sanctuaries natural habitats aur organisms ko protect karne mein help karte hain. Conservation se biodiversity ko maintain karne mein support milta hai.<br><br>Example: Ek wildlife sanctuary animals ko hunting aur habitat destruction jaise threats se protection provide kar sakti hai."
}

];

let currentQuestion = 0;
let score = 0;
let userAnswers = [];
let userName = "";

function startQuiz() {
  userName = document.getElementById("userName").value.trim();

  if (!userName) return alert("Please enter your name.");

  document.getElementById("nameSection").style.display = "none";
  document.getElementById("quizSection").style.display = "block";

  showQuestion();
  loadScoreboard();
}

function showQuestion() {
  const q = questions[currentQuestion];
  const container = document.getElementById("questionContainer");

  container.innerHTML = `
    <div class="question">${q.question}</div>
    <div class="options">
      ${q.options.map((opt, i) => `
        <label>
          <input type="radio" name="option" value="${i}"
          ${userAnswers[currentQuestion] == i ? 'checked' : ''}>
          ${opt}
        </label>
      `).join('')}
    </div>
    <div class="explanation" id="explain${currentQuestion}">${q.explanation}</div>
  `;

  document.getElementById("prevBtn").style.display =
    currentQuestion === 0 ? "none" : "inline-block";

  document.getElementById("nextBtn").style.display =
    currentQuestion === questions.length - 1 ? "none" : "inline-block";

  document.getElementById("submitBtn").style.display =
    currentQuestion === questions.length - 1 ? "inline-block" : "none";
}

function nextQuestion() {
  saveAnswer();

  if (currentQuestion < questions.length - 1) {
    currentQuestion++;
    showQuestion();
  }
}

function prevQuestion() {
  saveAnswer();

  if (currentQuestion > 0) {
    currentQuestion--;
    showQuestion();
  }
}

function saveAnswer() {
  const selected = document.querySelector('input[name="option"]:checked');

  userAnswers[currentQuestion] =
    selected ? parseInt(selected.value) : null;
}

function submitQuiz() {
  saveAnswer();

  score = 0;

  questions.forEach((q, index) => {
    if (userAnswers[index] === q.correct) score++;
  });

  showResults();
  saveScore(userName, score);
  loadScoreboard();
}

function showResults() {
  const container = document.getElementById("questionContainer");
  container.innerHTML = "";

  questions.forEach((q, index) => {
    const selected = userAnswers[index];
    const correct = q.correct;

    let optsHTML = q.options.map((opt, i) => {
      let cls = "";

      if (i === correct) cls = "correct";

      if (selected === i && selected !== correct) {
        cls = "wrong";
      }

      return `<label class="${cls}">${opt}</label>`;
    }).join('');

    container.innerHTML += `
      <div class="question">${q.question}</div>
      <div class="options">${optsHTML}</div>
      <div class="explanation" style="display:block;">
        ${q.explanation}
      </div>
      <hr>
    `;
  });

  document.querySelector(".controls").style.display = "none";

  document.getElementById("result").innerHTML =
    `<h3>Your Score: ${score} / ${questions.length}</h3>`;
}

function saveScore(name, score) {
  let scores = JSON.parse(localStorage.getItem("quizScores")) || [];

  scores.push({
    name,
    score,
    date: new Date().toLocaleString()
  });

  localStorage.setItem("quizScores", JSON.stringify(scores));
}

function loadScoreboard() {
  let scores = JSON.parse(localStorage.getItem("quizScores")) || [];

  scores.sort((a, b) => b.score - a.score);

  document.getElementById("scoreList").innerHTML =
    scores.map(s =>
      `<li>${s.name} - ${s.score}/10 (${s.date})</li>`
    ).join('');
}
</script>
</body>
</html>

Leave a Comment