جواب «Too Short» چالش 2 از جلسهی 19
سؤال
اسم کاربری باید دستکم ۳ حرف باشد. زیر کادر، با && این خط را فقط وقتی نشان بده که nick کمتر از ۳ حرف دارد:<p id="hint" className="bad">Too short</p>
راهنما
زیر input بنویس: {nick.length < 3 && <p id="hint" className="bad">Too short</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 [nick, setNick] = useState("");
return (
<div>
<input id="nick" value={nick} onChange={(event) => setNick(event.target.value)} />
{nick.length < 3 && <p id="hint" className="bad">Too short</p>}
</div>
);
}
createRoot(document.getElementById("root")).render(<App />);
</script>
اول خودت امتحان کن؛ جوابهای دیگر هم قبول است. برگرد و خودت حلش کن