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

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

این برنامه باید هوا را بگوید:
- دمای بزرگ‌تر از 30: Hot
- دمای بزرگ‌تر از 15: Nice
- بقیه: Cold
ولی برای 35 می‌نویسد Cold و برای 5 می‌نویسد Nice! دو اشتباه دارد: یک کلمه جا افتاده و یک علامت برعکس است. پیدا و درستشان کن.

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

<input id="temp" placeholder="temperature">
<button id="go" onclick="press()">Go</button>
<p id="msg"></p>

<script>
let line = document.getElementById("msg");

function press() {
  let temp = Number(document.getElementById("temp").value);
  if (temp > 30) {
    line.textContent = "Hot";
  }
  if (temp < 15) {
    line.textContent = "Nice";
  } else {
    line.textContent = "Cold";
  }
}
</script>

راهنما و جواب این چالش · برگشت به درس جلسه‌ی 11: وگرنه

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