about the remove() function,how can i del the last element only?
The issue you're facing is because in the event handler for the Remove button, you are calling remove() on the taskList, which is the ul containing all your tasks. This will remove the entire ul element from the DOM, thereby deleting all tasks.
Instead, you should remove only the last task added to the list. Here's how you can do it:
<!DOCTYPE html>
<html>
  <head>
    <title>To-Do List</title>
  </head>
  <body>
    <h1>To-Do List</h1>`
    <input type="text" class="task" placeholder="Enter a task">
    <button class="Add">Add Task</button>
    <button class="removeTask">Remove</button>
    <ul class="taskList"></ul>
  </body>
  <script>
    const taskList = document.querySelector(".taskList");
    const RemoveEl = document.querySelector(".removeTask");
    const addTask = document.querySelector(".Add");

    addTask.addEventListener("click", () => {
      const taskInput = document.querySelector(".task");
      const newTask = document.createElement("li");
      let task = taskInput.value;

      if (task.trim() != "") {
        newTask.innerText = task;
        taskList.appendChild(newTask);
        taskInput.value = "";
      }
    });

    RemoveEl.addEventListener("click", () => {
      if (taskList.lastChild) {
        taskList.lastChild.remove();
      }
    });
  </script>
</html>

This updated script adds an event listener to the Remove button outside of the Add button's event listener. When the Remove button is clicked, it checks if there is a last child element in the task list (the last task added). If there is, it removes that element, leaving the rest of the task list intact.

I have the problem is that,When i press remove button,whole list is deleted,
for example,i add ABC and DEF,this 2 parts,
I press one time and ABC also gone!
how can i fix it?
<!DOCTYPE html>
<html>
  <head>
    <title>To-Do List</title>
  </head>
  <body>
    <h1>To-Do List</h1>`
    <input type="text" class="task" placeholder="Enter a task">
    <button class="Add">Add Task</button>
    <button class="removeTask">Remove</button>
    <ul class="taskList"></ul>
  </body>
  <script>



const taskList = document.querySelector(".taskList");
const RemoveEl = document.querySelector(".removeTask");
const addTask = document.querySelector(".Add");


addTask.addEventListener("click", (e)=>{ 
  const taskInput = document.querySelector(".task");
const newTask = document.createElement("li");
let task = taskInput.value;

  if (task.trim() != "") {
    
    newTask.innerText = task;
    taskList.appendChild(newTask);
    taskInput.value = "";};
  
    if(newTask){
  RemoveEl.addEventListener("click",()=>{

    taskList.remove();

  })
}});
  </script>
</html>

thank you so much!
