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

Step 1: Start and the First Question چالش 1 از جلسه‌ی 40، متوسط

صفحه‌ی شروع آماده است، ولی دکمه‌ی Start کاری نمی‌کند.
1. در App یک state به اسم screen بساز که اول "start" است. دکمه‌ی #start آن را "quiz" کند (تابع را با prop به اسم onStart به Start بده).
2. کامپوننت Quiz را بنویس که یک prop به اسم question می‌گیرد و این را برمی‌گرداند: یک div با id برابر quiz و کلاس card، داخلش یک h2 با id برابر question (متن سؤال) و برای هر گزینه یک دکمه با کلاس option و id برابر opt0، opt1، opt2.
3. وقتی صفحه "quiz" است، App به‌جای صفحه‌ی شروع، Quiz را با اولین سؤال نشان بدهد.

<style>
body { font-family: sans-serif; text-align: center; padding: 16px; }
button, input, select { font-size: 16px; min-height: 40px; margin: 4px; }
.card { max-width: 260px; margin: 12px auto; padding: 16px; border: 2px solid #334155; border-radius: 16px; background: #f8fafc; }
.option { min-width: 90px; }
.right { background: #bbf7d0; }
.wrong { background: #fecaca; }
</style>

<div id="root" dir="ltr"></div>

<script type="text/jsx">
import { useState } from "react";
import { createRoot } from "react-dom/client";

const QUESTIONS = [
  { id: 1, text: "What colour is the sky?", options: ["Green", "Blue", "Red"], answer: 1 },
  { id: 2, text: "How many legs does a spider have?", options: ["Eight", "Six", "Ten"], answer: 0 },
  { id: 3, text: "Which planet do we live on?", options: ["Mars", "Venus", "Earth"], answer: 2 },
];

function Start() {
  return (
    <div id="start-screen" className="card">
      <h1>Sky Quiz</h1>
      <p>{QUESTIONS.length} questions</p>
      <button id="start">Start</button>
    </div>
  );
}

function App() {
  return <Start />;
}

createRoot(document.getElementById("root")).render(<App />);
</script>

راهنما و جواب این چالش · برگشت به درس جلسه‌ی 40: پروژه: کوییز من با ری‌اکت · چالش بعدی: Step 2: Answer and Score

بیشتر بخوان: جاوااسکریپت چیست؟ از دکمه‌ی وب تا Node.js