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

Find the Bugs چالش 6 از جلسه‌ی 24، سخت

ریسه کامل روشن است. این برنامه باید چهار لامپ آخر (شماره‌های ۹ و ۸ و ۷ و ۶) را خاموش کند و روی تابلو بنویسد چند لامپ روشن مانده است (6). ولی با خطا می‌ایستد.
دو اشتباه دارد: یکی در خط let i و یکی در شرط while. هر دو را پیدا و درست کن.

<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; }
.board { font-size: 40px; width: 200px; margin: 12px auto; padding: 10px; border-radius: 12px; background: #e2e8f0; }
</style>

<div id="lights" class="lights">
  <span class="bulb on"></span>
  <span class="bulb on"></span>
  <span class="bulb on"></span>
  <span class="bulb on"></span>
  <span class="bulb on"></span>
  <span class="bulb on"></span>
  <span class="bulb on"></span>
  <span class="bulb on"></span>
  <span class="bulb on"></span>
  <span class="bulb on"></span>
</div>
<div id="board" class="board">0</div>

<script>
let bulbs = document.querySelectorAll(".bulb");
let i = 10;

while (i > 6) {
  bulbs[i].classList.remove("on");
  i--;
}

document.getElementById("board").textContent = i + 1;
</script>

راهنما و جواب این چالش · برگشت به درس جلسه‌ی 24: حلقه‌ی while

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