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

مثال JavaScript: <button id="go" onclick="press()">Go</butto… — اگر 2 3

مثال 4 از درس جلسه‌ی 10 آموزش جاوااسکریپت از صفر برای نوجوانان، با لامپ و چراغ راهنما: اگر

برای «برابر است؟» سه علامت مساوی می‌نویسیم: ===. اینجا اگر کلمه‌ی open را بنویسی در باز می‌شود. متن را با متن مقایسه می‌کنیم، پس "open" داخل گیومه است و حروف کوچک و بزرگش هم مهم است: Open قبول نیست.

<style>
body { font-family: sans-serif; text-align: center; padding: 16px; }
button, input, select { font-size: 16px; min-height: 40px; margin: 4px; }
.door { font-size: 70px; width: 110px; margin: 12px auto; border-radius: 12px; background: #92400e; }
.door.open { background: #86efac; }
</style>

<div id="door" class="door">🚪</div>
<input id="word" placeholder="the word">
<button id="go" onclick="press()">Go</button>

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

function press() {
  let word = document.getElementById("word").value;
  if (word === "open") {
    door.classList.add("open");
  }
}
</script>

این کد را همین‌جا در ویرایشگر HTML اجرا کن، عددها و متن‌هایش را عوض کن و دوباره اجرا کن تا ببینی چه تغییری می‌کند.

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

← مثال قبلی · برگشت به درس جلسه‌ی 10: اگر · مثال بعدی → · چالش‌های این جلسه