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

Describe and Warm چالش 5 از جلسه‌ی 28، سخت

دو شیء داریم که هر کدام سه فیلد دارند: name، temp و on. دکمه‌های Info جوابِ describe(room) را در #msg می‌نویسند. دکمه‌ی Warm اول warm(room) را صدا می‌زند و بعد همان را نشان می‌دهد.
دو تابع بنویس:
- describe(room): متنی مثل Kitchen: 22 degrees, off برگرداند (اگر on درست است، آخرش on).
- warm(room): دمای اتاق را ۲ تا زیاد کند و on را true کند.

<style>
body { font-family: sans-serif; text-align: center; padding: 16px; }
button, input, select { font-size: 16px; min-height: 40px; margin: 4px; }
</style>

<button id="info-a" onclick="info(roomA)">Info: kitchen</button>
<button id="info-b" onclick="info(roomB)">Info: bath</button>
<button id="warm-a" onclick="heat(roomA)">Warm the kitchen</button>
<p id="msg"></p>

<script>
const roomA = { name: "Kitchen", temp: 22, on: false };
const roomB = { name: "Bath", temp: 25, on: true };

function describe(room) {
  // your code here
}

function warm(room) {
  // your code here
}

function info(room) {
  document.getElementById("msg").textContent = describe(room);
}

function heat(room) {
  warm(room);
  info(room);
}
</script>

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

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