The House Obeys the Text چالش 5 از جلسهی 36، سخت
متن داخل کادر یک آرایهی JSON از id اتاقهاست، مثل ["kitchen","bath"]. با زدن Apply:
- متن را به آرایه تبدیل کن.
- اول همهی اتاقها را خاموش کن (با document.querySelectorAll(".room") و یک حلقه).
- بعد فقط اتاقهایی را که id آنها در آرایه هست روشن کن.
<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; }
#box { width: 280px; max-width: 100%; }
</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>
<input id="box" value='["kitchen","bath"]'>
<button id="apply" onclick="apply()">Apply</button>
<script>
let box = document.getElementById("box");
function apply() {
// your code here
}
</script>
راهنما و جواب این چالش · برگشت به درس جلسهی 36: جِیسان: داده به شکل متن · چالش بعدی: Find the Bugs
بیشتر بخوان: جاوااسکریپت چیست؟ از دکمهی وب تا Node.js