بتل کد Battle Codeدارد باز می‌شود…

Step 4: Test, Fix, Label چالش 4 از جلسه‌ی 12، سخت

هوش مصنوعی کد را «مرتب» کرد و هم‌گروهی‌ات موقع آزمودن دید سؤال پنجم هیچ‌وقت نمی‌آید؛ بعد از چهار جواب، بازی تمام می‌شود! باگ را پیدا و درست کن (به شرط if در pick نگاه کن). بعد پایین صفحه یک <footer> با دو پاراگراف بگذار: اولی با AI: شروع شود و دومی با Me:.

<h1>Know Your AI</h1>
<p id="question">Press Start!</p>
<div id="answers"></div>
<p id="score"></p>
<button id="start">Start</button>

<script>
const questions = [
  { q: "Can an AI chat bot make up facts?", options: ["Yes", "No", "Only on Fridays"], answer: 0 },
  { q: "Should you tell a chat bot your password?", options: ["Yes", "Only if it asks nicely", "Never"], answer: 2 },
  { q: "What is a deepfake?", options: ["A fake photo or voice made by AI", "A deep pool", "A kind of fish"], answer: 0 },
  { q: "Who should check what an AI says?", options: ["Nobody", "You, with a book or a teacher", "Another AI only"], answer: 1 },
  { q: "Using AI for homework is honest when...", options: ["You hide it", "It teaches you and you say so", "It writes everything"], answer: 1 },
];
let score = 0;
let current = 0;

function show() {
  const item = questions[current];
  document.getElementById("question").textContent = item.q;
  const box = document.getElementById("answers");
  box.innerHTML = "";
  item.options.forEach(function (text, i) {
    const b = document.createElement("button");
    b.textContent = text;
    b.onclick = function () { pick(i); };
    box.appendChild(b);
  });
}

function pick(i) {
  if (i === questions[current].answer) {
    score = score + 1;
  }
  document.getElementById("score").textContent = "Score: " + score;
  current = current + 1;
  if (current < questions.length - 1) {
    show();
  } else {
    document.getElementById("question").textContent = "Done! Score: " + score + " / " + questions.length;
    document.getElementById("answers").innerHTML = "";
  }
}

document.getElementById("start").onclick = function () {
  current = 0;
  score = 0;
  document.getElementById("score").textContent = "Score: 0";
  show();
};
</script>

<style>
body { font-family: sans-serif; padding: 16px; }
#answers { display: flex; flex-wrap: wrap; gap: 8px; }
button { min-height: 40px; padding: 8px 14px; font-size: 16px; }
</style>

راهنما و جواب این چالش · برگشت به درس جلسه‌ی 12: پروژه: بازی مسابقه‌ی «هوش مصنوعی را بشناس»

بیشتر بخوان: شرط if، elif و else در پایتون: آموزش کامل با مثال