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

Your Name چالش 5 از جلسه‌ی 8، متوسط

اپ با #hello سلام می‌کند. اگر اسمی ذخیره نشده بگوید Hi!، وگرنه مثل Hi, Sara!. وقتی #saveName زده شد، اسم کوچک کادر #name را (با trim) با اسم "name" ذخیره کن و سلام را عوض کن. موقع باز شدن اسم را با salam.load("name", "") بخوان.

<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
body { font-family: Tahoma, sans-serif; max-width: 420px; margin: 0 auto; padding: 12px; }
li { padding: 8px 0; font-size: 18px; }

form { display: flex; column-gap: 8px; }
input { font-size: 16px; min-height: 44px; }
input[type="checkbox"] { min-height: 0; width: 24px; height: 24px; }
button { font-size: 16px; min-height: 44px; }
</style>
<h1 id="hello"></h1>
<input id="name" placeholder="Your first name">
<button id="saveName" onclick="saveName()">Save</button>
<script>
function greet(name) {
  // show "Hi!" when there is no name, or "Hi, Sara!" for Sara
}

function saveName() {
  let name = document.getElementById("name").value.trim();
}
</script>

راهنما و جواب این چالش · برگشت به درس جلسه‌ی 8: ذخیره · چالش بعدی: Clear Everything

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