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

Light by Word چالش 5 از جلسه‌ی 11، سخت

حالا چراغ راهنما با یک کلمه روشن می‌شود. خاموش کردن چراغ‌ها و پاک کردن پیام آماده است. بقیه با توست:
- کلمه را از color بخوان.
- red چراغ قرمز، yellow چراغ زرد و green چراغ سبز را روشن کند.
- با هر کلمه‌ی دیگری هیچ چراغی روشن نشود و در msg نوشته شود Unknown color.

<style>
body { font-family: sans-serif; text-align: center; padding: 16px; }
button, input, select { font-size: 16px; min-height: 40px; margin: 4px; }
.traffic { width: 70px; margin: 12px auto; padding: 10px; border-radius: 16px; background: #1e293b; }
.light { width: 50px; height: 50px; margin: 8px auto; border-radius: 50%; background: #64748b; }
#red.on { background: red; }
#yellow.on { background: gold; }
#green.on { background: limegreen; }
</style>

<div class="traffic">
  <div id="red" class="light"></div>
  <div id="yellow" class="light"></div>
  <div id="green" class="light"></div>
</div>
<input id="color" placeholder="red, yellow or green">
<button id="go" onclick="press()">Go</button>
<p id="msg"></p>

<script>
let red = document.getElementById("red");
let yellow = document.getElementById("yellow");
let green = document.getElementById("green");
let line = document.getElementById("msg");

function press() {
  red.classList.remove("on");
  yellow.classList.remove("on");
  green.classList.remove("on");
  line.textContent = "";

}
</script>

راهنما و جواب این چالش · برگشت به درس جلسه‌ی 11: وگرنه · چالش بعدی: Find the Bugs

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