class 9 science chapter 4

ch4 part9

<!DOCTYPE html>
<html lang="en">
<head>
<title>🧠 Science Quiz – Graphical Representation of Motion</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 – Graphical Representation of Motion</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. Motion ko graphically represent karne ka main advantage kya hai?",
    options: [
      "A. Sirf object ka mass find karna",
      "B. Position, velocity aur acceleration mein time ke saath changes ko visually represent karna",
      "C. Sirf distance ko measure karna",
      "D. Sirf object ka colour identify karna"
    ],
    correct: 1,
    explanation: "Graphs motion ko visual form mein show karte hain aur position, velocity aur acceleration ke changes ko samajhne mein help karte hain."
  },
  {
    question: "2. Table mein ek vehicle ki position 0 s par 0 m, 1 s par 20 m, 2 s par 40 m aur 3 s par 60 m hai. Position-time graph banate waqt time ko kis axis par represent kiya jaayega?",
    options: [
      "A. Y-axis",
      "B. Z-axis",
      "C. X-axis",
      "D. Origin par"
    ],
    correct: 2,
    explanation: "Position-time graph mein time X-axis par aur position Y-axis par represent ki jaati hai."
  },
  {
    question: "3. Position-time graph mein vertical Y-axis par kya represent kiya jaayega jab horizontal X-axis par time represent kiya gaya ho?",
    options: [
      "A. Position",
      "B. Time",
      "C. Mass",
      "D. Acceleration only"
    ],
    correct: 0,
    explanation: "Position-time graph mein generally time X-axis par aur position Y-axis par li jaati hai."
  },
  {
    question: "4. Graph paper par do perpendicular lines X-axis aur Y-axis ko draw kiya gaya hain. In dono lines ka intersection point kya kehlata hai?",
    options: [
      "A. Scale",
      "B. Origin O",
      "C. Slope",
      "D. Position point"
    ],
    correct: 1,
    explanation: "X-axis aur Y-axis ka intersection point origin O kehlata hai."
  },
  {
    question: "5. Vehicle ke position-time graph ke liye X-axis par 5 divisions = 1 s aur Y-axis par 5 divisions = 20 m ka scale choose kiya gaya. 3 s aur 60 m ko represent karne ke liye kaunsa point plot karna hoga?",
    options: [
      "A. (3 s, 20 m)",
      "B. (20 s, 3 m)",
      "C. (3 s, 60 m)",
      "D. (60 s, 3 m)"
    ],
    correct: 2,
    explanation: "Graph par point ko (time, position) ke form mein plot kiya jaata hai. Yahan time = 3 s aur position = 60 m."
  },
  {
    question: "6. Table mein vehicle ki position 0 s par 0 m di gayi hai. Position-time graph mein is information ko kis point se represent kiya jaayega?",
    options: [
      "A. Origin O",
      "B. X-axis par 20 m",
      "C. Y-axis par 1 s",
      "D. (20, 20) point"
    ],
    correct: 0,
    explanation: "Time = 0 s aur position = 0 m dono zero hain, isliye point origin O par plot hoga."
  },
  {
    question: "7. Kisi graph par time = 1 s aur position = 20 m ka point plot karna hai. Is point ko accurately locate karne ke liye kya kiya jaata hai?",
    options: [
      "A. Sirf X-axis par 20 m mark karte hain",
      "B. 1 s se Y-axis ke parallel aur 20 m se X-axis ke parallel lines draw karke intersection locate karte hain",
      "C. Sirf Y-axis par 1 s mark karte hain",
      "D. Origin ko hata dete hain"
    ],
    correct: 1,
    explanation: "X-axis par 1 s aur Y-axis par 20 m locate karke corresponding parallel lines draw karte hain. Dono lines ka intersection required point hota hai."
  },
  {
    question: "8. Vehicle ke data mein time 0, 1, 2, 3, 4, 5, 6 s ke corresponding positions 0, 20, 40, 60, 80, 100, 120 m hain. Sabhi points ko plot karke join karne par graph kaisa milega?",
    options: [
      "A. Straight line",
      "B. Circle",
      "C. Zig-zag line",
      "D. Closed curve"
    ],
    correct: 0,
    explanation: "Har equal time interval mein position 20 m se increase ho rahi hai. Isliye plotted points ek straight line form karte hain."
  },
  {
    question: "9. Graph banate waqt scale choose karne ka main purpose kya hai?",
    options: [
      "A. Graph ko bina data ke banana",
      "B. Data ko available graph-paper space mein accurately aur conveniently represent karna",
      "C. Sirf X-axis ko bada karna",
      "D. Sirf Y-axis ko remove karna"
    ],
    correct: 1,
    explanation: "Suitable scale se data ko graph paper par accurately, clearly aur conveniently plot kiya ja sakta hai."
  },
  {
    question: "10. Position-time graph banane ka correct sequence kaunsa hai?",
    options: [
      "A. Points plot karo → axes hatao → scale choose karo → line draw karo",
      "B. Axes draw karo → quantities decide karo → suitable scale choose karo → values mark karo → points plot karo → points join karo",
      "C. Scale choose karo → graph paper hatao → points guess karo",
      "D. Sirf X-axis draw karke graph complete karo"
    ],
    correct: 1,
    explanation: "Position-time graph banane ke liye pehle axes, phir quantities aur scale decide karte hain, values mark karke points plot karte hain aur finally points ko join karke graph banate hain."
  }
];

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