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

جواب «Mark Done Items» چالش 4 از جلسه‌ی 5

سؤال

کار دوم انجام شده است (done: true). render() را عوض کن تا به li هر کار انجام‌شده کلاس done بدهد. CSS کلاس done آماده است و رویش خط می‌کشد.

راهنما

داخل for: if (todos[i].done) li.classList.add("done");

یک جواب درست

<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; }

.done { text-decoration: line-through; color: gray; }
</style>
<h1>My Tasks</h1>
<ul id="list"></ul>
<script>
let todos = [
  { text: "Feed the cat", done: false },
  { text: "Read a book", done: true },
  { text: "Tidy my desk", done: false },
];

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;
    if (todos[i].done) li.classList.add("done");
    list.appendChild(li);
  }
}

render();
</script>

اول خودت امتحان کن؛ جواب‌های دیگر هم قبول است. برگرد و خودت حلش کن