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

Colour the String چالش 4 از جلسه‌ی 21، متوسط

یک ریسه با پنج لامپ و یک آرایه با پنج رنگ داری.
با یک حلقه‌ی for رنگ هر لامپ را عوض کن: لامپ شماره‌ی i رنگ شماره‌ی i را بگیرد (با style.backgroundColor).

<style>
body { font-family: sans-serif; text-align: center; padding: 16px; }
button, input, select { font-size: 16px; min-height: 40px; margin: 4px; }
.lights { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; margin: 12px auto; }
.bulb { width: 34px; height: 34px; border-radius: 50%; background: #64748b; }
.bulb.on { background: #fde047; }
</style>

<div id="lights" class="lights">
  <span class="bulb"></span>
  <span class="bulb"></span>
  <span class="bulb"></span>
  <span class="bulb"></span>
  <span class="bulb"></span>
</div>

<script>
let colors = ["red", "orange", "gold", "limegreen", "dodgerblue"];
let bulbs = document.querySelectorAll(".bulb");
</script>

راهنما و جواب این چالش · برگشت به درس جلسه‌ی 21: آرایه‌ها · چالش بعدی: Add and Undo

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