Step 2: Show the Question چالش 2 از جلسهی 12، متوسط
تابع show() بنویس (میتوانی از هوش مصنوعی بخواهی، ولی خط به خط بخوانش): متن سؤال questions[current] را در #question بگذارد، #answers را خالی کند و برای هر گزینه یک <button> بسازد که با کلیک pick(i) را صدا بزند. pick فعلاً فقط current را یکی زیاد کند و اگر سؤال مانده show() کند. کلیک روی #start هم current = 0 و show().
<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 },
];
document.getElementById("start").onclick = function () {
document.getElementById("score").textContent = questions.length + " questions";
};
</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: پروژه: بازی مسابقهی «هوش مصنوعی را بشناس» · چالش بعدی: Step 3: Score and the Final Message
بیشتر بخوان: شرط if، elif و else در پایتون: آموزش کامل با مثال