Find the Bugs چالش 6 از جلسهی 26، سخت
این برنامه باید روی آشپزخانه بنویسد Cooking و روی اتاق خواب بنویسد Sleeping. دکمه هم باید روی حمام بنویسد Busy. ولی هیچکدام کار نمیکند.
دو اشتباه دارد. هر دو را پیدا و درست کن. (راهنمایی: یکی داخل تابع است و یکی در صدا زدنِ آن.)
<style>
body { font-family: sans-serif; text-align: center; padding: 16px; }
button, input, select { font-size: 16px; min-height: 40px; margin: 4px; }
.house { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; max-width: 340px; margin: 12px auto; }
.room { width: 150px; padding: 18px 0; border-radius: 12px; background: #334155; color: white; }
.room.on { background: #fde047; color: black; }
</style>
<div class="house">
<div id="kitchen" class="room">Kitchen</div>
<div id="bedroom" class="room">Bedroom</div>
<div id="living" class="room">Living room</div>
<div id="bath" class="room">Bath</div>
</div>
<button id="busy" onclick="label('bath', 'Busy')">Bath is busy</button>
<script>
function label(id, text) {
let room = document.getElementById("id");
room.textContent = text;
}
label("kitchen", "Cooking");
label("Sleeping", "bedroom");
</script>
راهنما و جواب این چالش · برگشت به درس جلسهی 26: تابع با ورودی
بیشتر بخوان: جاوااسکریپت چیست؟ از دکمهی وب تا Node.js