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

جواب «Strong or Weak» چالش 4 از جلسه‌ی 19

سؤال

یک رمزسنج بساز. رمز در state به اسم pass است و کادر به آن وصل است.
خط #state را کامل کن:
- اگر رمز ۶ حرف یا بیشتر است: متن Strong و کلاس good
- وگرنه: متن Weak و کلاس bad

state تازه نساز؛ از روی pass.length حساب کن.

راهنما

قبل از return: const strong = pass.length >= 6;. بعد: <p id="state" className={strong ? "good" : "bad"}>{strong ? "Strong" : "Weak"}</p>

یک جواب درست

<style>
body { font-family: sans-serif; text-align: center; padding: 16px; }
button, input, select { font-size: 16px; min-height: 40px; margin: 4px; }
.good { color: green; }
.bad { color: crimson; }
</style>

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

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

function App() {
  const [pass, setPass] = useState("");
  const strong = pass.length >= 6;
  return (
    <div>
      <input id="pass" value={pass} onChange={(event) => setPass(event.target.value)} />
      <p id="state" className={strong ? "good" : "bad"}>{strong ? "Strong" : "Weak"}</p>
    </div>
  );
}

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

اول خودت امتحان کن؛ جواب‌های دیگر هم قبول است. برگرد و خودت حلش کن