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

Push and Draw چالش 1 از جلسه‌ی 6، آسان

تابع add را کامل کن: متن کادر #t را به شکل { text: text, done: false } با push به todos اضافه کن و بعد render() را صدا بزن.

<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>My Tasks</h1>
<form id="addForm" onsubmit="add(event)">
  <input id="t" placeholder="New task">
  <button>Add</button>
</form>
<ul id="list"></ul>
<script>
let todos = [];

function render() {
  let list = document.getElementById("list");
  list.textContent = "";
  for (let i = 0; i < todos.length; i++) {
    let li = document.createElement("li");
    li.textContent = todos[i].text;
    list.appendChild(li);
  }
}

function add(event) {
  event.preventDefault();
  let text = document.getElementById("t").value;
  // put the new task in the array, then draw the list again
}

render();
</script>

راهنما و جواب این چالش · برگشت به درس جلسه‌ی 6: افزودن · چالش بعدی: Empty the Box

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