class 8th, subject science,ch4

ch4part1


<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>🧠 Magnetic Effect of Electric Current Quiz</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;
    margin: 0;
  }

  .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;
    line-height: 1.6;
  }

  .options label {
    display: block;
    margin: 8px 0;
    padding: 10px;
    border-radius: 6px;
    border: 1px solid #ccc;
    cursor: pointer;
    transition: 0.3s;
    line-height: 1.5;
  }

  .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;
    line-height: 1.6;
  }

  .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; }

  @media (max-width: 600px) {
    body { padding: 12px; }
    .quiz-container { width: 100%; padding: 15px; }
  }
</style>
</head>

<body>

<div class="quiz-container">

  <h2>🧠 Magnetic Effect of Electric Current Quiz</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. Jab electric current wire mein flow karta hai, toh wire ke around kya produce hota hai?",
    options: [
      "A. Sirf sound",
      "B. Magnetic field",
      "C. Sirf light",
      "D. Water vapour"
    ],
    correct: 1,
    explanation: "Jab electric current conductor, jaise wire, se flow karta hai, toh uske around magnetic field produce hoti hai. Is phenomenon ko magnetic effect of electric current kehte hain.<br><br><b>Example:</b> Current-carrying wire ke paas rakhi compass needle deflect kar sakti hai."
  },

  {
    question: "2. Circuit ka switch ON karne par magnetic compass ki needle mein kya change hota hai?",
    options: [
      "A. Needle deflect hoti hai",
      "B. Needle melt ho jaati hai",
      "C. Needle ka magnetism hamesha ke liye khatam ho jaata hai",
      "D. Needle disappear ho jaati hai"
    ],
    correct: 0,
    explanation: "Switch ON karne par circuit complete hota hai aur wire mein current flow karta hai. Wire ki magnetic field compass needle ki direction ko change kar sakti hai.<br><br><b>Example:</b> Compass needle north direction mein point kar rahi ho, toh current ON karne par woh apni original direction se turn kar sakti hai."
  },

  {
    question: "3. Switch OFF karne par compass needle generally kya karti hai?",
    options: [
      "A. Hamesha rotate karti rehti hai",
      "B. Wire se chipak jaati hai",
      "C. Apni original direction mein laut aati hai",
      "D. Apna colour change kar leti hai"
    ],
    correct: 2,
    explanation: "Switch OFF karne par current ruk jaata hai. Current ke kaaran produce hua magnetic effect disappear ho jaata hai, isliye compass needle generally apni original direction mein laut aati hai.<br><br><b>Example:</b> Switch ko ON aur OFF karne par compass needle ki position mein change observe kiya ja sakta hai."
  },

  {
    question: "4. Magnetic compass ki needle asal mein kya hoti hai?",
    options: [
      "A. Ek electric cell",
      "B. Ek plastic strip",
      "C. Ek ordinary iron wire",
      "D. Ek chhota magnet"
    ],
    correct: 3,
    explanation: "Compass needle ek tiny magnet hoti hai. Isliye woh nearby magnetic field ke influence mein apni direction change kar sakti hai.<br><br><b>Example:</b> Jab compass ke paas magnet laate hain, toh needle deflect hoti hai."
  },

  {
    question: "5. Magnetic field kise kehte hain?",
    options: [
      "A. Wire ke andar ka empty space",
      "B. Magnet ya current-carrying wire ke around ka region jahan magnetic effect feel ho sakta hai",
      "C. Sirf battery ke andar ka region",
      "D. Aisa region jahan gravity nahi hoti"
    ],
    correct: 1,
    explanation: "Magnetic field woh region hai jahan magnetic effect detect kiya ja sakta hai, jaise compass needle ke deflection se.<br><br><b>Example:</b> Current-carrying wire ke paas compass rakhkar uski needle ka deflection observe karna magnetic field ka evidence hai."
  },

  {
    question: "6. Electric current ke magnetic effect ko investigate karne ke liye kaunsa instrument use kiya gaya?",
    options: [
      "A. Magnetic compass",
      "B. Thermometer",
      "C. Measuring cylinder",
      "D. Spring balance"
    ],
    correct: 0,
    explanation: "Magnetic compass ki needle magnetic field ke influence mein deflect hoti hai. Isliye iska use current-carrying wire ke magnetic effect ko detect karne ke liye kiya ja sakta hai.<br><br><b>Example:</b> Wire ke neeche compass rakhkar switch ON karne par needle ki direction observe kar sakte hain."
  },

  {
    question: "7. Experiment mein switch ka main function kya hai?",
    options: [
      "A. Wire ka colour change karna",
      "B. Compass ko charge karna",
      "C. Circuit ko open ya close karke current ko control karna",
      "D. Magnetic field ko measure karna"
    ],
    correct: 2,
    explanation: "Switch ON karne par circuit complete hota hai aur current flow karta hai. Switch OFF karne par circuit open ho jaata hai aur current flow ruk jaata hai.<br><br><b>Example:</b> Room ka light switch ON karne par circuit complete hota hai aur bulb glow karta hai."
  },

  {
    question: "8. Current-carrying wire ke magnetic effect ka sabse suitable evidence kya hai?",
    options: [
      "A. Wire ka colour change hona",
      "B. Battery ka size badalna",
      "C. Cardboard ka shape change hona",
      "D. Wire ke paas compass needle ka deflect hona"
    ],
    correct: 3,
    explanation: "Compass needle magnet hoti hai. Uski direction change hona indicate karta hai ki wire ke current se magnetic effect produce ho raha hai.<br><br><b>Example:</b> Current OFF hone par needle original direction mein laut sakti hai, aur current ON hone par phir deflect ho sakti hai."
  },

  {
    question: "9. Magnetic effect of electric current kaunsa statement correctly explain karta hai?",
    options: [
      "A. Current sirf heat produce karta hai",
      "B. Conductor mein current flow hone par uske around magnetic field produce hoti hai",
      "C. Magnetic field sirf permanent magnets se produce hoti hai",
      "D. Current flow hone par magnetic field kabhi produce nahi hoti"
    ],
    correct: 1,
    explanation: "Electric current aur magnetism ke beech connection hota hai. Current-carrying conductor apne around magnetic field create karta hai.<br><br><b>Example:</b> Electromagnet mein wire se current pass karke magnetic effect ka use iron objects ko attract karne ke liye kiya ja sakta hai."
  },

  {
    question: "10. Current-carrying wire ki magnetic field ke baare mein kaunsa statement correct hai?",
    options: [
      "A. Current band hone par current-produced magnetic field disappear ho jaati hai",
      "B. Current band hone ke baad bhi magnetic field hamesha same rehti hai",
      "C. Magnetic field sirf plastic mein produce hoti hai",
      "D. Magnetic field ka compass needle par koi effect nahi hota"
    ],
    correct: 0,
    explanation: "Is activity mein wire ki magnetic field electric current ke kaaran produce hoti hai. Current rukne par yeh magnetic effect disappear ho jaata hai, aur compass needle original direction mein laut aati hai.<br><br><b>Example:</b> Battery se connected simple electromagnet ka current band karne par uska magnetic effect bahut kam ho jaata hai."
  }

];

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

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 saveAnswer() {
  const selected = document.querySelector('input[name="option"]:checked');
  userAnswers[currentQuestion] = selected ? parseInt(selected.value) : null;
}

function nextQuestion() {
  saveAnswer();

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

function prevQuestion() {
  saveAnswer();

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

function submitQuiz() {
  if (submitted) return;

  saveAnswer();
  score = 0;

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

  submitted = true;
  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 escapeHTML(value) {
  return String(value).replace(/[&<>"']/g, char => ({
    "&": "&amp;",
    "<": "&lt;",
    ">": "&gt;",
    '"': "&quot;",
    "'": "&#39;"
  })[char]);
}

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>${escapeHTML(s.name)} - ${s.score}/10 (${escapeHTML(s.date)})</li>`
    ).join("");
}

</script>

</body>
</html>

ch4part2

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>🧠 Electromagnet Quiz</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;
  margin: 0;
}
.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; line-height: 1.6; }
.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;
  line-height: 1.6;
}
.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; }
#userName {
  padding: 10px;
  width: 65%;
  max-width: 300px;
  border: 1px solid #ccc;
  border-radius: 6px;
}
@media (max-width: 600px) {
  body { padding: 12px; }
  .quiz-container { width: 100%; padding: 16px; }
}
</style>
</head>

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

<h2>🧠 Science Quiz – Electromagnet</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. Electromagnet banane ke liye iron nail ke around kya tightly wind kiya jaata hai?",
  options: [
    "A. Plastic strip",
    "B. Cotton thread",
    "C. Insulated wire",
    "D. Paper sheet"
  ],
  correct: 2,
  explanation: "Insulated wire ko iron nail ke around coil ke form mein wind kiya jaata hai. Jab wire mein electric current flow karta hai, toh magnetic effect produce hota hai.<br><br><strong>Example:</strong> Wire-wrapped iron nail ko cell se connect karne par woh iron paper clips ko attract kar sakta hai."
},

{
  question: "2. Electromagnet kab magnetic effect show karta hai?",
  options: [
    "A. Jab coil mein electric current flow karta hai",
    "B. Jab wire ko cell se disconnect kar diya jaata hai",
    "C. Jab coil mein current bilkul nahi hota",
    "D. Jab iron nail ko plastic se replace kar diya jaata hai"
  ],
  correct: 0,
  explanation: "Current-carrying coil ke around magnetic field produce hoti hai. Isliye coil magnet ki tarah behave karti hai.<br><br><strong>Example:</strong> Cell se connected coil iron clips ko attract kar sakti hai."
},

{
  question: "3. Electromagnet mein iron nail insert karne se kya effect hota hai?",
  options: [
    "A. Coil ka current hamesha stop ho jaata hai",
    "B. Coil ka magnetic effect khatam ho jaata hai",
    "C. Wire electricity conduct karna band kar deti hai",
    "D. Electromagnet stronger ho jaata hai"
  ],
  correct: 3,
  explanation: "Iron nail coil ke andar magnetic field ko strengthen karne mein help karta hai. Isse electromagnet ka magnetic effect increase hota hai.<br><br><strong>Example:</strong> Iron core wali coil generally bina iron core wali coil se zyada strongly iron clips attract kar sakti hai."
},

{
  question: "4. Current-carrying coil ke paas rakhi magnetic compass needle deflect kyon hoti hai?",
  options: [
    "A. Coil se sound produce hoti hai",
    "B. Coil ke around magnetic field produce hoti hai",
    "C. Compass needle electrically charge ho jaati hai",
    "D. Coil ka colour change hota hai"
  ],
  correct: 1,
  explanation: "Compass needle ek chhota magnet hoti hai. Coil ki magnetic field uski direction ko change kar sakti hai, jise deflection kehte hain.<br><br><strong>Example:</strong> Coil ko cell se connect karne par compass needle apni original direction se turn kar sakti hai."
},

{
  question: "5. Activity mein wire ke around cardboard cylinder banane ka main purpose kya hai?",
  options: [
    "A. Cell ko charge karna",
    "B. Iron clips ko store karna",
    "C. Wire ko cylindrical coil ke form mein wind karne ke liye support dena",
    "D. Compass needle ko lock karna"
  ],
  correct: 2,
  explanation: "Chart paper ko cylinder banakar wire uske around neatly wind ki ja sakti hai. Isse cylindrical coil banti hai.<br><br><strong>Example:</strong> Pencil ke around paper cylinder bana kar us par insulated wire ki multiple turns lapeti ja sakti hain."
},

{
  question: "6. Activity mein cylindrical coil par approximately kitne turns wire ke wind kiye gaye the?",
  options: [
    "A. 50 turns",
    "B. 5 turns",
    "C. 10 turns",
    "D. 500 turns"
  ],
  correct: 0,
  explanation: "Activity mein approximately 50 turns wire ke wind karke cylindrical coil banayi gayi thi. Coil ke turns ki sankhya magnetic field ki strength ko affect kar sakti hai.<br><br><strong>Example:</strong> Same current aur similar conditions mein coil ke turns increase karne se magnetic field generally stronger ho sakti hai."
},

{
  question: "7. Jab coil se electric current disconnect kiya jaata hai, toh compass needle generally kya karti hai?",
  options: [
    "A. Hamesha ek hi direction mein ghoomti rehti hai",
    "B. Coil ke andar chali jaati hai",
    "C. Permanent magnet ban jaati hai",
    "D. Apni original direction mein laut aati hai"
  ],
  correct: 3,
  explanation: "Current stop hone par coil ka current-produced magnetic effect disappear ho jaata hai. Isliye compass needle generally apni original direction mein return karti hai.<br><br><strong>Example:</strong> Switch OFF karne par electromagnet ka magnetic effect bahut kam ho jaata hai aur iron clips gir sakti hain."
},

{
  question: "8. Current-carrying coil jo magnet ki tarah behave karti hai, use kya kehte hain?",
  options: [
    "A. Electric cell",
    "B. Electromagnet",
    "C. Insulator",
    "D. Magnetic compass"
  ],
  correct: 1,
  explanation: "Electric current se magnetic effect produce karne wali coil ko electromagnet kehte hain. Practical applications mein iski strength badhane ke liye commonly iron core use hota hai.<br><br><strong>Example:</strong> Electromagnet ka use scrap-yard crane mein iron aur steel objects ko lift karne ke liye kiya ja sakta hai."
},

{
  question: "9. Electromagnet ki magnetic strength ko improve karne ke liye commonly kya use kiya jaata hai?",
  options: [
    "A. Wooden core",
    "B. Rubber core",
    "C. Iron core",
    "D. Paper core only"
  ],
  correct: 2,
  explanation: "Iron core coil ke magnetic effect ko stronger banane mein help karta hai. Isi wajah se practical electromagnets mein commonly iron core use hota hai.<br><br><strong>Example:</strong> Iron nail ko current-carrying coil ke andar insert karne par coil stronger magnet ki tarah behave kar sakti hai."
},

{
  question: "10. Battery se connected wire ko sirf kuch seconds ke liye connect karne ki warning kyon di gayi hai?",
  options: [
    "A. Zyada der tak connection se high current flow ho sakta hai, jis se cell weak aur wire hot ho sakti hai",
    "B. Isse iron nail wooden nail ban jaata hai",
    "C. Isse compass permanently damage hona certain hai",
    "D. Isse wire ka insulation automatically disappear ho jaata hai"
  ],
  correct: 0,
  explanation: "Low-resistance circuit mein current zyada ho sakta hai. Isse cell jaldi discharge ho sakta hai aur wire heat ho sakti hai. Isliye circuit ko briefly connect karein aur battery terminals ko directly short-circuit na karein.<br><br><strong>Example:</strong> Coil ko cell se connect karke observation karein, phir wire ko disconnect kar dein."
}

];

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

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

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

  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 saveAnswer() {
  const selected = document.querySelector('input[name="option"]:checked');
  userAnswers[currentQuestion] = selected ? parseInt(selected.value) : null;
}

function nextQuestion() {
  saveAnswer();

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

function prevQuestion() {
  saveAnswer();

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

function submitQuiz() {
  if (submitted) return;

  saveAnswer();
  score = 0;

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

  submitted = true;
  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>${escapeHTML(s.name)} - ${s.score}/10 (${escapeHTML(s.date)})</li>`
    ).join("");
}

function escapeHTML(value) {
  return String(value).replace(/[&<>"']/g, char => ({
    "&": "&amp;",
    "<": "&lt;",
    ">": "&gt;",
    '"': "&quot;",
    "'": "&#39;"
  })[char]);
}
</script>

</body>
</html>

ch4part3

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>🧠 Science Quiz – Electromagnet</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; line-height: 1.6; }
.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;
  line-height: 1.6;
}
.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; }

@media (max-width: 600px) {
  body { padding: 12px; }
  .quiz-container { width: 100%; padding: 16px; }
}
</style>
</head>

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

<h2>🧠 Science Quiz – Electromagnet & Earth's Magnetic Field</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. An electromagnet ke kitne poles hote hain?",
  options: [
    "A. Sirf one pole",
    "B. Three poles",
    "C. Two poles — North and South",
    "D. Four poles"
  ],
  correct: 2,
  explanation: "Permanent magnet ki tarah electromagnet ke bhi do poles hote hain: North aur South. Inki polarity current ki direction par depend karti hai.<br><br><strong>Example:</strong> Electromagnet ke ek end par North pole aur doosre end par South pole ho sakta hai."
},

{
  question: "2. Agar compass ka North pole electromagnet ke end A ki taraf attract hota hai, toh end A kaunsa pole hoga?",
  options: [
    "A. South pole",
    "B. North pole",
    "C. Dono poles",
    "D. Koi pole nahi"
  ],
  correct: 0,
  explanation: "Unlike poles ek-doosre ko attract karte hain, jabki like poles repel karte hain. Isliye compass ka North pole agar end A ki taraf attract ho, toh end A South pole hoga.<br><br><strong>Example:</strong> North pole aur South pole paas laane par ek-doosre ko attract karte hain."
},

{
  question: "3. Electromagnet ke end A aur end B ki polarity generally kaisi hoti hai?",
  options: [
    "A. Dono ends hamesha North hote hain",
    "B. Dono ends hamesha South hote hain",
    "C. Dono ends par koi polarity nahi hoti",
    "D. Ek North aur doosra South hota hai"
  ],
  correct: 3,
  explanation: "Electromagnet ke do opposite poles hote hain. Ek end North hota hai aur doosra South.<br><br><strong>Example:</strong> Agar end A North hai, toh end B South hoga."
},

{
  question: "4. Same coil mein cells ki sankhya badhane se electromagnet ki strength par kya effect ho sakta hai?",
  options: [
    "A. Strength hamesha zero ho jaati hai",
    "B. Magnetic field stronger ho sakti hai",
    "C. Coil plastic ban jaati hai",
    "D. Compass ka magnetic effect khatam ho jaata hai"
  ],
  correct: 1,
  explanation: "Suitable conditions mein cells ki sankhya badhane se current increase ho sakta hai. Isse magnetic field stronger ho sakti hai aur compass needle ka deflection badh sakta hai.<br><br><strong>Example:</strong> Same coil mein suitable battery supply badhane par electromagnet zyada iron clips attract kar sakta hai."
},

{
  question: "5. Coil mein wire ke turns ki sankhya badhane se kya hota hai?",
  options: [
    "A. Electromagnet hamesha weak ho jaata hai",
    "B. Electric current automatically zero ho jaata hai",
    "C. Electromagnet ki strength increase ho sakti hai",
    "D. Coil ka magnetic effect impossible ho jaata hai"
  ],
  correct: 2,
  explanation: "Same current aur similar conditions mein coil ke turns badhane se magnetic field generally stronger hoti hai.<br><br><strong>Example:</strong> 50 turns wali coil ko suitable conditions mein 100 turns wali coil se compare karne par zyada turns wali coil stronger magnetic effect produce kar sakti hai."
},

{
  question: "6. Electromagnet ke poles ko reverse karne ke liye kya change karna chahiye?",
  options: [
    "A. Current ki direction",
    "B. Cardboard ka colour",
    "C. Nail ki length ko hamesha double karna",
    "D. Compass ko remove karna"
  ],
  correct: 0,
  explanation: "Coil mein current ki direction reverse karne par electromagnet ke North aur South poles interchange ho jaate hain.<br><br><strong>Example:</strong> Agar pehle end A North tha, toh current reverse karne par end A South ban sakta hai."
},

{
  question: "7. Compass needle ka deflection zyada hone ka kya meaning ho sakta hai?",
  options: [
    "A. Compass toot gaya hai",
    "B. Battery mein current nahi hai",
    "C. Coil ka size zero ho gaya hai",
    "D. Compass par magnetic field ka effect zyada strong hai"
  ],
  correct: 3,
  explanation: "Experiment ki conditions same hon, toh compass needle ka greater deflection coil ke stronger magnetic field ko indicate kar sakta hai.<br><br><strong>Example:</strong> More current ya more coil turns se magnetic field stronger ho sakti hai, jisse compass needle zyada deflect kar sakti hai."
},

{
  question: "8. Earth ka magnetic field mainly kaise generate hota hai?",
  options: [
    "A. Clouds ki movement se",
    "B. Earth ke liquid outer core mein moving electrically conducting material se",
    "C. Mountains ke colour se",
    "D. Moonlight se"
  ],
  correct: 1,
  explanation: "Earth ke liquid outer core mein iron-rich conducting material ki movement electric currents produce karti hai. Ye currents Earth ka magnetic field generate karne mein help karte hain.<br><br><strong>Example:</strong> Compass needle Earth ke magnetic field ke influence mein approximately north–south direction mein align hoti hai."
},

{
  question: "9. Earth ka magnetic field migratory birds aur kuch animals ke liye kaise useful hai?",
  options: [
    "A. Unhe food automatically provide karta hai",
    "B. Unki body ka temperature hamesha same rakhta hai",
    "C. Navigation mein help kar sakta hai",
    "D. Unhe flying ki zaroorat se free kar deta hai"
  ],
  correct: 2,
  explanation: "Kuch migratory birds, fish aur animals Earth ke magnetic field ko navigation ke liye use kar sakte hain. Isse unhe long distances par direction identify karne mein help mil sakti hai.<br><br><strong>Example:</strong> Kuch migratory birds apni seasonal migration ke dauraan Earth ke magnetic field se milne wale signals ka use kar sakte hain."
},

{
  question: "10. Earth ke magnetic field ka ek important role kya hai?",
  options: [
    "A. Space se aane wale charged particles ke harmful effects ko kam karne mein help karna",
    "B. Earth par gravity ko completely stop karna",
    "C. Sunlight ko completely block karna",
    "D. Ocean water ko permanently freeze karna"
  ],
  correct: 0,
  explanation: "Earth ka magnetic field kai charged particles ko deflect karta hai aur magnetosphere banata hai. Isse Earth ke aas-paas ka environment harmful solar particles se kuch protection paata hai.<br><br><strong>Example:</strong> Solar wind ke charged particles Earth ke magnetic field se interact karte hain, jisse polar regions mein aurora jaise natural light displays bhi ho sakte hain."
}

];

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

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

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

  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 saveAnswer() {
  const selected = document.querySelector('input[name="option"]:checked');
  userAnswers[currentQuestion] = selected ? parseInt(selected.value) : null;
}

function nextQuestion() {
  saveAnswer();

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

function prevQuestion() {
  saveAnswer();

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

function submitQuiz() {
  if (submitted) return;

  saveAnswer();
  score = 0;

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

  submitted = true;
  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>${escapeHTML(s.name)} - ${s.score}/10 (${escapeHTML(s.date)})</li>`
    ).join("");
}

function escapeHTML(value) {
  return String(value).replace(/[&<>"']/g, char => ({
    "&": "&amp;",
    "<": "&lt;",
    ">": "&gt;",
    '"': "&quot;",
    "'": "&#39;"
  })[char]);
}
</script>

</body>
</html>

ch4part4

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>🧠 Science Quiz – Lifting Electromagnet</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;
    margin: 0;
  }

  .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;
    line-height: 1.6;
  }

  .options label {
    display: block;
    margin: 8px 0;
    padding: 10px;
    border-radius: 6px;
    border: 1px solid #ccc;
    cursor: pointer;
    transition: 0.3s;
    line-height: 1.5;
  }

  .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;
    line-height: 1.6;
  }

  .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;
  }

  input[type="text"] {
    padding: 10px;
    width: 60%;
    max-width: 300px;
    border: 1px solid #ccc;
    border-radius: 6px;
  }

  #scoreboard {
    margin-top: 25px;
    background: #eef3f7;
    padding: 15px;
    border-radius: 8px;
  }

  #scoreboard h3 {
    text-align: center;
  }

  ol {
    padding-left: 20px;
  }

  hr {
    border: none;
    border-top: 1px solid #ddd;
    margin: 20px 0;
  }

  @media (max-width: 600px) {
    body {
      padding: 10px;
    }

    .quiz-container {
      width: 100%;
      padding: 15px;
    }
  }
</style>
</head>

<body>

<div class="quiz-container">

  <h2>🧠 Science Quiz – Lifting Electromagnet & Electricity</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. Lifting electromagnet ka main use kya hai?",
    options: [
      "A. Water ko purify karna",
      "B. Heavy iron aur steel objects ko lift karna",
      "C. Plastic ko melt karna",
      "D. Air ko cool karna"
    ],
    correct: 1,
    explanation: "Lifting electromagnets powerful electromagnets hote hain jo heavy iron aur steel objects ko lift aur move karne ke liye use kiye jaate hain.<br><br><strong>Example:</strong> Scrap yard mein crane ka electromagnet heavy iron rods aur steel sheets ko utha sakta hai."
  },

  {
    question: "2. Lifting electromagnet ko commonly kis machine par lagaya jaata hai?",
    options: [
      "A. Crane",
      "B. Refrigerator",
      "C. Bicycle",
      "D. Water filter"
    ],
    correct: 0,
    explanation: "Lifting electromagnet ko crane se attach kiya ja sakta hai. Crane operator current control karke metal objects ko lift aur release kar sakta hai.<br><br><strong>Example:</strong> Factory mein crane ek jagah se doosri jagah steel ke heavy parts move karti hai."
  },

  {
    question: "3. Jab lifting electromagnet mein electric current ON hota hai, toh kya hota hai?",
    options: [
      "A. Magnetic field hamesha ke liye khatam ho jaati hai",
      "B. Magnet plastic ko iron mein convert karta hai",
      "C. Electromagnet metal ko attract nahi karta",
      "D. Electromagnet iron aur steel objects ko attract karke lift kar sakta hai"
    ],
    correct: 3,
    explanation: "Current flow karne par electromagnet ke around magnetic field produce hoti hai. Is field ki help se woh suitable iron aur steel objects ko attract kar sakta hai.<br><br><strong>Example:</strong> Current ON karne par crane ka magnet steel ke tukdon ko utha sakta hai."
  },

  {
    question: "4. Jab lifting electromagnet ka current OFF kar diya jaata hai, toh kya hota hai?",
    options: [
      "A. Magnetic field aur strong ho jaati hai",
      "B. Electromagnet permanent magnet ban jaata hai",
      "C. Magnetic field disappear ho jaati hai aur objects release ho sakte hain",
      "D. Crane ka size badh jaata hai"
    ],
    correct: 2,
    explanation: "Current OFF karne par electromagnet ka magnetic effect disappear ho jaata hai, isliye woh objects ko release kar sakta hai.<br><br><strong>Example:</strong> Crane metal ko required place par le jaakar current OFF karti hai, jisse metal neeche gir jaata hai."
  },

  {
    question: "5. Lifting electromagnets ka use kahan widely hota hai?",
    options: [
      "A. Scrap yards aur factories mein",
      "B. Sirf swimming pools mein",
      "C. Sirf gardens mein",
      "D. Sirf classrooms mein"
    ],
    correct: 0,
    explanation: "Factories aur scrap yards mein heavy metal objects ko move, lift aur sort karne ke liye lifting electromagnets ka use hota hai.<br><br><strong>Example:</strong> Scrap yard mein crane mixed metal waste mein se iron aur steel items ko alag karne mein help karti hai."
  },

  {
    question: "6. Lifting electromagnet ka sabse important advantage kya hai?",
    options: [
      "A. Yeh bina electricity ke hamesha kaam karta hai",
      "B. Isse current ON/OFF karke magnetic effect control kiya ja sakta hai",
      "C. Yeh har material ko attract karta hai",
      "D. Yeh kabhi heat produce nahi kar sakta"
    ],
    correct: 1,
    explanation: "Electromagnet ka magnetic effect electric current ko control karke ON ya OFF kiya ja sakta hai. Isi wajah se metal objects ko lift aur release karna easy hota hai.<br><br><strong>Example:</strong> Crane metal ko lift karne ke liye current ON aur use chhodne ke liye current OFF karti hai."
  },

  {
    question: "7. Electric current flow karne par conductor ke around kya produce hota hai?",
    options: [
      "A. Sirf sound waves",
      "B. Sirf light",
      "C. Magnetic field",
      "D. Sirf water vapour"
    ],
    correct: 2,
    explanation: "Jab electric current kisi conductor, jaise wire, se flow karta hai, toh uske around magnetic field produce hoti hai.<br><br><strong>Example:</strong> Current-carrying wire ke paas magnetic compass rakhne par needle deflect kar sakti hai."
  },

  {
    question: "8. Electricity aur magnetism ke beech kya relationship hai?",
    options: [
      "A. Dono ka kabhi koi connection nahi hota",
      "B. Electricity sirf heat produce karti hai",
      "C. Magnetism se electricity par kabhi effect nahi hota",
      "D. Electric current magnetic field produce kar sakta hai, aur changing magnetic field electric current induce kar sakti hai"
    ],
    correct: 3,
    explanation: "Electricity aur magnetism closely connected hain. Current magnetic field produce karta hai. Moving magnet ya changing magnetic field suitable conditions mein conductor mein electric current induce kar sakti hai.<br><br><strong>Example:</strong> Generator mein magnetic field aur coil ke relative motion se electricity generate ki ja sakti hai."
  },

  {
    question: "9. Electric motor ka main function kya hota hai?",
    options: [
      "A. Electrical energy ko mechanical energy mein convert karna",
      "B. Mechanical energy ko hamesha sound mein convert karna",
      "C. Water ko metal mein convert karna",
      "D. Magnetic field ko completely remove karna"
    ],
    correct: 0,
    explanation: "Electric motor electrical energy ka use karke motion produce karti hai. Isliye motors fans, mixers aur kai machines mein use hoti hain.<br><br><strong>Example:</strong> Electric fan mein motor electrical energy ko rotating motion mein convert karti hai."
  },

  {
    question: "10. Electric generator ka main function kya hota hai?",
    options: [
      "A. Electricity ko permanently store karna",
      "B. Mechanical energy se electrical energy generate karna",
      "C. Sirf iron objects ko lift karna",
      "D. Current ko hamesha zero rakhna"
    ],
    correct: 1,
    explanation: "Generator mechanical energy ka use karke electrical energy produce karta hai. Ismein electromagnetic induction ka principle use hota hai.<br><br><strong>Example:</strong> Power station mein turbine ki movement generator ko chalati hai, jisse electrical energy generate hoti hai."
  }

];

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

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

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

  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, 10) : null;
}

function submitQuiz() {
  if (submitted) return;

  saveAnswer();

  score = 0;

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

  submitted = true;

  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 escapeHTML(value) {
  return String(value).replace(/[&<>"']/g, char => ({
    "&": "&amp;",
    "<": "&lt;",
    ">": "&gt;",
    '"': "&quot;",
    "'": "&#39;"
  })[char]);
}

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>${escapeHTML(s.name)} - ${s.score}/10
      (${escapeHTML(s.date)})</li>
    `).join("");
}

</script>

</body>
</html>

ch4part5

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>🧠 Science Quiz – Heating Effect of Electric Current</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;
    margin: 0;
  }

  .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;
    line-height: 1.6;
  }

  .options label {
    display: block;
    margin: 8px 0;
    padding: 10px;
    border-radius: 6px;
    border: 1px solid #ccc;
    cursor: pointer;
    transition: 0.3s;
    line-height: 1.5;
  }

  .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;
    line-height: 1.6;
  }

  .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;
  }

  input[type="text"] {
    padding: 10px;
    width: 60%;
    max-width: 300px;
    border: 1px solid #ccc;
    border-radius: 6px;
  }

  #scoreboard {
    margin-top: 25px;
    background: #eef3f7;
    padding: 15px;
    border-radius: 8px;
  }

  #scoreboard h3 {
    text-align: center;
  }

  ol {
    padding-left: 20px;
  }

  hr {
    border: none;
    border-top: 1px solid #ddd;
    margin: 20px 0;
  }

  @media (max-width: 600px) {
    body {
      padding: 10px;
    }

    .quiz-container {
      width: 100%;
      padding: 15px;
    }
  }
</style>
</head>

<body>

<div class="quiz-container">

  <h2>🧠 Science Quiz – Heating Effect of Electric Current</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. Nichrome wire mein electric current flow karne par kya hota hai?",
    options: [
      "A. Wire thandi ho jaati hai",
      "B. Wire gayab ho jaati hai",
      "C. Wire warm ya hot ho jaati hai",
      "D. Wire plastic ban jaati hai"
    ],
    correct: 2,
    explanation: "Jab electric current kisi conductor se flow karta hai, toh usmein resistance ke kaaran electrical energy ka kuch part heat energy mein convert ho jaata hai.<br><br><strong>Example:</strong> Electric heater mein current flow karne par heating element garam ho jaata hai."
  },

  {
    question: "2. Activity 4.5 mein kis type ki wire use ki gayi hai?",
    options: [
      "A. Nichrome wire",
      "B. Cotton thread",
      "C. Plastic wire",
      "D. Rubber strip"
    ],
    correct: 0,
    explanation: "Is activity mein nichrome wire use hoti hai, kyunki same size aur length ki copper wire ke comparison mein nichrome wire higher resistance offer karti hai.<br><br><strong>Example:</strong> Electric heater aur toaster mein nichrome jaise resistance wires heating ke liye use ki jaati hain."
  },

  {
    question: "3. Nichrome wire ko warm feel karne ke liye switch ko ON position mein approximately kitni der rakhna hai?",
    options: [
      "A. 2 seconds",
      "B. 30 seconds",
      "C. 5 minutes",
      "D. 1 hour"
    ],
    correct: 1,
    explanation: "Activity mein switch ko lagbhag 30 seconds ke liye ON kiya jaata hai, phir OFF karke wire ke temperature mein difference observe kiya jaata hai.<br><br><strong>Example:</strong> Current flow karne ke baad wire pehle se zyada warm feel ho sakti hai.<br><br><strong>Safety:</strong> Garam nichrome wire ko haath mein pakadkar touch nahi karna chahiye. Textbook activity ko teacher ki supervision mein safely perform karein."
  },

  {
    question: "4. Electric current ke flow ka opposition kya kehlata hai?",
    options: [
      "A. Magnetism",
      "B. Reflection",
      "C. Evaporation",
      "D. Resistance"
    ],
    correct: 3,
    explanation: "Resistance conductor ki woh property hai jo electric current ke flow ka opposition karti hai. Different conductors ka resistance different ho sakta hai.<br><br><strong>Example:</strong> Same size aur length ki nichrome wire ka resistance copper wire se zyada hota hai."
  },

  {
    question: "5. Same length aur thickness ki nichrome wire aur copper wire mein se generally kiski resistance zyada hoti hai?",
    options: [
      "A. Nichrome wire",
      "B. Copper wire",
      "C. Dono ka resistance hamesha zero hota hai",
      "D. Dono ka resistance hamesha equal hota hai"
    ],
    correct: 0,
    explanation: "Nichrome, copper ke comparison mein current ke flow ko zyada oppose karta hai. Isliye same length aur thickness par nichrome ka resistance generally higher hota hai.<br><br><strong>Example:</strong> Copper wires electrical connections mein commonly use hoti hain, jabki nichrome heating elements mein use hoti hai."
  },

  {
    question: "6. Electric current ke heating effect ka main reason kya hai?",
    options: [
      "A. Electrical energy ka sound energy mein convert hona",
      "B. Electrical energy ka kuch part heat energy mein convert hona",
      "C. Wire ka colour change hona",
      "D. Magnetic compass ka move karna"
    ],
    correct: 1,
    explanation: "Conductor mein current flow karne par resistance ke kaaran electrical energy ka kuch part heat energy mein convert ho jaata hai. Isi ko heating effect of electric current kehte hain.<br><br><strong>Example:</strong> Electric iron mein current se heating element garam hota hai aur kapdon ki wrinkles remove karne mein help karta hai."
  },

  {
    question: "7. Heating effect of electric current ka correct meaning kya hai?",
    options: [
      "A. Current se conductor hamesha freeze ho jaata hai",
      "B. Current conductor ka mass khatam kar deta hai",
      "C. Current flow karne par conductor heat produce karke warm ho sakta hai",
      "D. Current sirf light produce karta hai"
    ],
    correct: 2,
    explanation: "Current-carrying conductor mein electrical energy heat energy mein convert ho sakti hai. Heat ki amount resistance, current aur time par depend karti hai.<br><br><strong>Example:</strong> Electric kettle mein heating element current flow karne par paani ko garam karta hai."
  },

  {
    question: "8. Nichrome wire ko current pass karne se pehle aur baad mein observe karne ka purpose kya hai?",
    options: [
      "A. Wire ki length ko double karna",
      "B. Wire ko magnet banana hi ekmatra purpose hai",
      "C. Wire ka colour ya shape badalna",
      "D. Current flow hone par temperature mein change observe karna"
    ],
    correct: 3,
    explanation: "Switch OFF hone par wire comparatively cool hoti hai. Current ko kuch der ON rakhne par wire warm ho sakti hai. Isse heating effect observe hota hai.<br><br><strong>Example:</strong> Heater ko ON karne par uska heating element garam hota hai, jabki OFF karne par dheere-dheere cool hota hai."
  },

  {
    question: "9. Electric heating effect ka use kis device mein hota hai?",
    options: [
      "A. Electric iron",
      "B. Simple wooden ruler",
      "C. Glass marble",
      "D. Paper notebook"
    ],
    correct: 0,
    explanation: "Electric iron mein current-carrying heating element electrical energy ko heat energy mein convert karta hai. Yeh heat kapdon ko press karne mein use hoti hai.<br><br><strong>Example:</strong> Electric iron ka base garam hota hai aur kapdon ki creases smooth karne mein help karta hai."
  },

  {
    question: "10. Agar kisi conductor mein current flow karna band ho jaaye, toh heating ka kya hoga?",
    options: [
      "A. Wire hamesha aur zyada garam hoti rahegi",
      "B. Electrical heating normally band ho jaayegi aur wire dheere-dheere cool ho sakti hai",
      "C. Wire automatically plastic ban jaayegi",
      "D. Wire ka resistance hamesha infinite ho jaayega"
    ],
    correct: 1,
    explanation: "Current OFF karne par electrical energy ka current-driven heating mein conversion ruk jaata hai. Wire apni surroundings ko heat transfer karke dheere-dheere cool ho sakti hai.<br><br><strong>Example:</strong> Electric heater ko switch OFF karne ke baad bhi uska element kuch samay tak warm reh sakta hai, phir thanda ho jaata hai."
  }

];

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

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

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

  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, 10) : null;
}

function submitQuiz() {
  if (submitted) return;

  saveAnswer();

  score = 0;

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

  submitted = true;

  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 escapeHTML(value) {
  return String(value).replace(/[&<>"']/g, char => ({
    "&": "&amp;",
    "<": "&lt;",
    ">": "&gt;",
    '"': "&quot;",
    "'": "&#39;"
  })[char]);
}

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>${escapeHTML(s.name)} - ${s.score}/10
      (${escapeHTML(s.date)})</li>
    `).join("");
}

</script>

</body>
</html>

ch4part6

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>🧠 Science Quiz – Heating Effect of Electric Current</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;
    line-height: 1.7;
}

.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;
}

.options input {
    margin-right: 8px;
}

.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;
    line-height: 1.6;
}

.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;
}

#result {
    text-align: center;
    margin-top: 20px;
    font-size: 18px;
    font-weight: bold;
}

</style>
</head>

<body>

<div class="quiz-container">

    <h2>🧠 Science Quiz – Heating Effect of Electric Current</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"></div>

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

    </div>
</div>

<script>

const questions = [

{
    question: "1. Incandescent lamp ka filament kis wajah se glow karta hai?",
    options: [
        "A. Paani ke contact mein aane se",
        "B. Electric current ke kaaran heat hone se",
        "C. Hawa ke pressure se",
        "D. Magnet ke attract karne se"
    ],
    correct: 1,
    explanation: "Explanation: Incandescent lamp mein electric current filament ko bahut zyada heat karta hai. Filament itna garam ho jaata hai ki glow karne lagta hai.<br><br>Example: Traditional incandescent bulb ko ON karne par uska filament bright light produce karta hai."
},

{
    question: "2. Electric room heater kis principle par work karta hai?",
    options: [
        "A. Heating effect of electric current",
        "B. Reflection of light",
        "C. Evaporation of water",
        "D. Gravitational force"
    ],
    correct: 0,
    explanation: "Explanation: Room heater mein current heating element se pass hota hai. Electrical energy heat energy mein convert hoti hai, jisse room warm hota hai.<br><br>Example: Sardi mein electric room heater room ka temperature badhane mein help karta hai."
},

{
    question: "3. Electric appliances mein heat produce karne wali wire ya coil ko kya kehte hain?",
    options: [
        "A. Switch",
        "B. Plug",
        "C. Heating element",
        "D. Fuse holder"
    ],
    correct: 2,
    explanation: "Explanation: Heating element ek rod ya wire ki coil hoti hai jo electric current pass hone par heat produce karti hai.<br><br>Example: Electric kettle aur electric iron mein heating element hota hai."
},

{
    question: "4. Inmein se kaunsa appliance heating effect of electric current par work karta hai?",
    options: [
        "A. Wooden chair",
        "B. Paper notebook",
        "C. Plastic scale",
        "D. Electric iron"
    ],
    correct: 3,
    explanation: "Explanation: Electric iron ka heating element current pass hone par garam hota hai. Yeh heat kapdon ki wrinkles remove karne mein help karti hai.<br><br>Example: Kapdon ko press karne ke liye electric iron use ki jaati hai."
},

{
    question: "5. Kuch appliances mein heating element red hot kyun dikhai deta hai?",
    options: [
        "A. Woh bahut zyada heat hone ke kaaran glow karta hai",
        "B. Usmein paani bhar jaata hai",
        "C. Uska resistance hamesha zero hota hai",
        "D. Usmein current flow nahi karta"
    ],
    correct: 0,
    explanation: "Explanation: Jab heating element ka temperature bahut high ho jaata hai, toh woh red hot glow kar sakta hai.<br><br>Example: Kuch electric stoves mein heating coil garam hone par red glow karti hai."
},

{
    question: "6. Inmein se kaunsa appliance water ko heat karne ke liye use hota hai?",
    options: [
        "A. Electric fan",
        "B. Electric kettle",
        "C. Wall clock",
        "D. Calculator"
    ],
    correct: 1,
    explanation: "Explanation: Electric kettle mein heating element electrical energy ko heat energy mein convert karta hai. Yeh heat water ka temperature badhati hai.<br><br>Example: Electric kettle mein chai banane ke liye paani garam kiya ja sakta hai."
},

{
    question: "7. Electric wires mein transmission ke dauran energy loss kis form mein ho sakta hai?",
    options: [
        "A. Sound energy",
        "B. Nuclear energy",
        "C. Heat energy",
        "D. Chemical energy only"
    ],
    correct: 2,
    explanation: "Explanation: Wires mein resistance hota hai. Current flow karne par electrical energy ka kuch part heat mein convert ho jaata hai, jisse transmission ke dauran energy loss hota hai.<br><br>Example: Long-distance power lines mein wires ke resistance ke kaaran kuch electrical energy heat ke roop mein lose hoti hai."
},

{
    question: "8. Electrical appliance ke overheat hone se kya problem ho sakti hai?",
    options: [
        "A. Plug aur socket ke plastic parts melt ho sakte hain",
        "B. Appliance hamesha cool ho jaata hai",
        "C. Electricity ka use completely band ho jaata hai",
        "D. Plastic parts aur strong ho jaate hain"
    ],
    correct: 0,
    explanation: "Explanation: Excessive heating se plugs aur sockets ke plastic parts damage ya melt ho sakte hain. Severe overheating se fire ka risk bhi ho sakta hai.<br><br>Example: Damaged plug ya loose connection se overheating ho sakti hai. Aise plug ko use nahi karna chahiye."
},

{
    question: "9. Household electrical circuits mein safety devices kyun lagaye jaate hain?",
    options: [
        "A. Appliances ka colour change karne ke liye",
        "B. Electricity ki speed ko zero karne ke liye",
        "C. Wires ko unnecessarily heat karne ke liye",
        "D. Electrical accidents aur overheating se hone wale damage ka risk kam karne ke liye"
    ],
    correct: 3,
    explanation: "Explanation: Fuse aur circuit breaker jaise safety devices excessive current hone par circuit ko disconnect kar sakte hain. Isse overheating, damage aur fire ka risk kam hota hai.<br><br>Example: Short circuit hone par circuit breaker trip karke electricity supply ko interrupt kar sakta hai."
},

{
    question: "10. Hair dryer mein heating effect ka kya role hota hai?",
    options: [
        "A. Sirf magnetic field produce karna",
        "B. Air ko heat karna, jabki fan air ko move karta hai",
        "C. Water ko electricity mein convert karna",
        "D. Current ko permanently store karna"
    ],
    correct: 1,
    explanation: "Explanation: Hair dryer mein heating element air ko warm karta hai aur fan us air ko bahar blow karta hai.<br><br>Example: Hair dryer se warm air nikalti hai, jo wet hair ko dry karne mein help karti hai."
}

];

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

function startQuiz() {

    userName = document.getElementById("userName").value.trim();

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

    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>
        <p>${score === 10 ? "Excellent! Perfect Score! 🏆" :
        score >= 7 ? "Very Good! Keep it up! 👏" :
        score >= 5 ? "Good effort! Keep practicing! 👍" :
        "Keep learning and try again! 📚"}</p>
    `;
}

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}/${questions.length} (${s.date})</li>`
        ).join('');
}

</script>

</body>
</html>

ch4part7

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>🧠 Science Quiz – Voltaic Cell</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; line-height: 1.6; }
.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; }
.options input { margin-right: 8px; }
.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;
    line-height: 1.6;
}
.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; }
#result {
    text-align: center;
    margin-top: 20px;
}
</style>
</head>

<body>

<div class="quiz-container">

<h2>🧠 Science Quiz – Voltaic Cell</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"></div>

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

</div>
</div>

<script>

const questions = [

{
question: "1. Voltaic cell ko aur kis naam se jaana jaata hai?",
options: [
"A. Magnetic cell",
"B. Heating cell",
"C. Galvanic cell",
"D. Solar cell"
],
correct: 2,
explanation: "Explanation: Voltaic cell ko Galvanic cell bhi kehte hain. Ismein chemical reaction ke through chemical energy electrical energy mein convert hoti hai.<br><br>Example: Ek simple voltaic cell chemical reaction ki help se connected bulb ko glow karne ke liye electricity supply kar sakta hai."
},

{
question: "2. Voltaic cell mein kitni metal rods ya electrodes hote hain?",
options: [
"A. Do",
"B. Ek",
"C. Chaar",
"D. Koi bhi nahi"
],
correct: 0,
explanation: "Explanation: Voltaic cell mein different materials ki do metal rods hoti hain. In rods ko electrodes kehte hain.<br><br>Example: Ek simple cell mein zinc aur copper ki rods electrodes ke roop mein use ki ja sakti hain."
},

{
question: "3. Voltaic cell mein electrodes ko kis liquid mein partly dip kiya jaata hai?",
options: [
"A. Cooking oil",
"B. Petrol",
"C. Pure honey",
"D. Electrolyte"
],
correct: 3,
explanation: "Explanation: Electrolyte ek liquid ya solution hota hai jo ions ki movement allow karta hai. Voltaic cell mein yeh usually weak acid ya salt solution ho sakta hai.<br><br>Example: Salt solution ek electrolyte ka example hai."
},

{
question: "4. Voltaic cell mein electrodes ko kya kehte hain?",
options: [
"A. Insulators",
"B. Electrodes",
"C. Switches",
"D. Filaments"
],
correct: 1,
explanation: "Explanation: Voltaic cell ki metal rods ko electrodes kaha jaata hai. Ye electrolyte ke contact mein rehte hain aur chemical reaction ke through electricity generate karne mein help karte hain.<br><br>Example: Zinc rod aur copper rod simple cell mein electrodes ke examples ho sakte hain."
},

{
question: "5. Voltaic cell mein electricity kis process ke through generate hoti hai?",
options: [
"A. Sirf heating se",
"B. Sirf friction se",
"C. Electrodes aur electrolyte ke beech chemical reaction se",
"D. Sirf sunlight se"
],
correct: 2,
explanation: "Explanation: Electrodes aur electrolyte ke beech chemical reaction hoti hai. Is reaction se chemical energy electrical energy mein convert ho sakti hai.<br><br>Example: Battery mein chemical reactions ki wajah se torch ka bulb glow kar sakta hai."
},

{
question: "6. Voltaic cell ka main function kya hai?",
options: [
"A. Chemical energy ko electrical energy mein convert karna",
"B. Electrical energy ko hamesha heat mein convert karna",
"C. Sound ko chemical energy mein convert karna",
"D. Water ko metal mein convert karna"
],
correct: 0,
explanation: "Explanation: Voltaic cell chemical reactions se electricity provide karta hai, jise external circuit mein use kiya ja sakta hai.<br><br>Example: Remote control ki battery electrical energy supply karke remote ko operate karne mein help karti hai."
},

{
question: "7. Jab voltaic cell ko complete circuit se connect kiya jaata hai, toh kya hota hai?",
options: [
"A. Electrolyte turant solid ban jaata hai",
"B. Electric current flow kar sakta hai",
"C. Electrodes disappear ho jaate hain",
"D. Circuit mein current kabhi flow nahi karta"
],
correct: 1,
explanation: "Explanation: Complete circuit milne par charges flow kar sakte hain, jisse electric current produce hota hai. Open circuit mein continuous current flow nahi karta.<br><br>Example: Cell ko wires aur bulb se connect karke circuit complete karne par bulb glow kar sakta hai."
},

{
question: "8. Textbook ke conventional current direction ke according, external circuit mein current kis terminal se kis terminal ki taraf flow karta hai?",
options: [
"A. Negative terminal se positive terminal",
"B. Dono terminals se kisi taraf nahi",
"C. Sirf electrolyte ke andar",
"D. Positive terminal se negative terminal"
],
correct: 3,
explanation: "Explanation: Conventional current external circuit mein positive terminal se negative terminal ki taraf maana jaata hai. Electrons metallic wire mein opposite direction mein move karte hain.<br><br>Example: Simple battery aur bulb wale circuit mein conventional current ki direction positive terminal se bulb ke through negative terminal ki taraf hoti hai."
},

{
question: "9. Jab voltaic cell ke chemicals use up ho jaate hain, toh kya hota hai?",
options: [
"A. Cell hamesha zyada electricity generate karta hai",
"B. Cell permanent magnet ban jaata hai",
"C. Cell electricity supply karna band kar sakta hai",
"D. Cell ka electrolyte plastic ban jaata hai"
],
correct: 2,
explanation: "Explanation: Cell ke andar chemical reactants dheere-dheere use hote hain. Jab reaction electricity provide karne ke liye sufficient nahi rehti, toh cell dead ho sakta hai.<br><br>Example: Remote ki battery weak ya dead hone par remote properly kaam karna band kar sakta hai."
},

{
question: "10. Inmein se kaunsa statement Voltaic cell ke baare mein correct hai?",
options: [
"A. Ismein chemical reaction electricity generate karne mein help karti hai",
"B. Ismein electrolyte ki koi role nahi hoti",
"C. Ismein sirf ek electrode hota hai",
"D. Yeh chemicals use hone ke baad bhi hamesha electricity deta hai"
],
correct: 0,
explanation: "Explanation: Voltaic cell mein electrodes aur electrolyte ke beech chemical reaction electrical energy provide karti hai. Chemicals use up hone par cell dead ho sakta hai.<br><br>Example: Ek dry cell flashlight ko electricity deta hai, lekin chemicals ki capacity khatam hone par cell replace karna pad sakta 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>
        <p>${score === 10 ? "Excellent! Perfect Score! 🏆" :
        score >= 7 ? "Very Good! Keep it up! 👏" :
        score >= 5 ? "Good effort! Keep practicing! 👍" :
        "Keep learning and try again! 📚"}</p>
    `;
}

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}/${questions.length} (${s.date})</li>`
        ).join('');
}

</script>

</body>
</html>

ch4part8

ch4part9

ch4part10

ch4part11

ch4part12

ch4part13

ch4part14

ch4part15

ch4part16

ch4part17

ch4part18

ch4part19

ch4part20

ch4part21

ch4part22

ch4part23

ch4part24

Leave a Comment