Liwei Su

Love writing Something

the origin repo is here.

this note records my questions and solutions of this project.

First two questions are:

  • what is the code const todoInput = document.querySelector(".todo-input") try to do?
  • what “event listeners” are (like the addEventListener parts)? or who listening the event?

The first one is to use dot selector to pass the todo-input-related to todoInput, and the code could use it for event listening logic writing. The second one is the browser that listening the event, the event listeners maybe a process of a browser, and when the code which contain addEventListener, browser then create a process for event listen. but actually I'm not sure the explain is right or not.

The whole things are: user write the content, and click the so called Send button, browser listening this button event, cuz the JS code we write is running in the browser, and the browser know, then execute the specific function, for example, addTodo.

Then another question is: if don't create div tag, what will happen?

If we change the code in addTodo from this:

todoDiv.appendChild(newTodo);
todoDiv.appendChild(completedButton);
todoDiv.appendChild(trashButton);
todoList.appendChild(todoDiv);

image-20251201145242811

to this:

todoList.appendChild(newTodo);
todoList.appendChild(completedButton);
todoList.appendChild(trashButton);

image-20251201145346573

which mean directly put the Send button, Delete button, and div on todoList. we could see: after changing the code, those three are divided, much ugly. Although I don't know why I refresh the page and everything become normal(maybe the browser is correcting my code).

Refactor

After read the function of getTodos, I know why after refresh. The page become normal because after refresh, the getTodos function is called, and there also a create todo logic in it, since there the logic is right, the page will still perform right.

But this also come up an issue that, there are repetitive codes in addTodo and getTodos, we can DRY that code.

I DRY that code myself, but seems some bugs occur, so I think I should read twice before coding.

Before, the functions addTodo and getTodos are looked like this:

function addTodo(e) {
  e.preventDefault();
  
  // Create todo div
  const todoDiv = document.createElement("div");
  todoDiv.classList.add("todo");
  
  // Create list
  const newTodo = document.createElement("li");
  newTodo.innerText = todoInput.value;
  
  // Save to local
  saveLocalTodos(todoInput.value);
  newTodo.classList.add("todo-item");
  todoDiv.appendChild(newTodo);
  todoInput.value = "";
  
  // Create Completed Button
  const completedButton = document.createElement("button");
  completedButton.innerHTML = `✓`;
  completedButton.classList.add("complete-btn");
  todoDiv.appendChild(completedButton);
  
  // Create trash button
  const trashButton = document.createElement("button");
  trashButton.innerHTML = `✗`;
  trashButton.classList.add("trash-btn");
  todoDiv.appendChild(trashButton);
  
  // Final Todo
  todoList.appendChild(todoDiv);
}

function getTodos() {
  let todos;
  
  if (localStorage.getItem("todos") === null) {
    todos = [];
  } else {
    todos = JSON.parse(localStorage.getItem("todos"));
  }
  
  todos.forEach(function (todo) {
    // Create todo div
    const todoDiv = document.createElement("div");
    todoDiv.classList.add("todo");
    
    // Create list
    const newTodo = document.createElement("li");
    newTodo.innerText = todo;
    newTodo.classList.add("todo-item");
    todoDiv.appendChild(newTodo);
    todoInput.value = "";
    
    // Create Completed Button
    const completedButton = document.createElement("button");
    completedButton.innerHTML = `✓`;
    completedButton.classList.add("complete-btn");
    todoDiv.appendChild(completedButton);
    
    // Create trash button
    const trashButton = document.createElement("button");
    trashButton.innerHTML = `✗`;
    trashButton.classList.add("trash-btn");
    todoDiv.appendChild(trashButton);
    
    // Final Todo
    todoList.appendChild(todoDiv);
  });

I think it's hard to refactor now, at least at this form.

About these code, here are some questions:

  • what is 'e' and what is preventDefault do?
  • why we need todoInput.value = "";

As we all know, when a button is submit type, its default action is submit the form to the remote server. But since here we only use local memory to keep the todo list, so don't need to do that. And the 'e' here is just a parameter to pass the related variable of clicking event define by browser.

Delete Myth

After commenting out the style.css link in index.html, I find a strange problem of this code: when I input, submit, and delete the note, it didn't delete at once, but after a refresh. Code is here:

function deleteTodo(e) {
  const item = e.target;

  if (item.classList[0] === "trash-btn") {
    const todo = item.parentElement;
    
    todo.classList.add("fall");
    todo.classList.add("completed");
    removeLocalTodos(todo);
    
    todo.addEventListener("transitionend", (e) => {
      todo.remove();
    });
  }
  
  if (item.classList[0] === "complete-btn") {
    const todo = item.parentElement;
    
    todo.classList.toggle("completed");
  }
}

Here I use console.log to test what is item, and found it is button. But something beyond my surprise:

const todo = item.parentElement;
console.log(todo)
todo.classList.add("fall");
todo.classList.add("completed");
console.log(todo)
removeLocalTodos(todo);

The first and the second log show the same content! which is a div have 3 class.

Last Word

Well, this project is poorly written, I give up reading it. Never, ever, read a rubbish project.

A long time after ChatGPT release, we heavily depending on all kinds of AI products.

  • At the end of my college year, 80% of my paper was written by AI.
  • After having a job(which is writting script), I use it to coding and give up coding myself.
  • During AdventureX 2025, most of the products(including ours) here were created by AI.
  • Even some Art Gallery start to put some so-called “AI-generated art” to show.
  • Lots of “vibe coders” emege, develop software seems a thing that everyone could do.

We are so damn rely it that we almost lost our own thinking.

Of course I know someone will argue: “then why don't you criticise Google, Facebook, or Tiktok?” My answer is, they only change the way we see the infomation. Or worst, they just push what we wanna hear or see, we could still read the other media. But using AI, most of people will lost their thinking ability.

Don't use, you lose. When AI start its deep thinking, who the hell will think by themself? Once people are not thinking by themself, they are just a AI-prompt speaker, say what AI say, do what AI suggest.

Here is a talk from TED, it hold the same point with me.

On Feb 24th, I finish my first time hackthon on Devpost, with other three friends.

On June 24th, I receive an invitation email from AdventureX 2025. On July 28th, I finished the five days hackathon in Hangzhou.

AdventureX 2025 invitation mail

Later, I joined a hackathon launched by Hackathon Weekly, a organization in Shenzhen.

I was excited, passionate, fall in love with these hackathons. I once hope that, in China, there will be more well-organized hackathons there waiting for people to join in. But now, what I wanna say is: Don't join any hackathon in China, and here are why.

Root weak here

Open Source community is weak in China, and due to the network policy, even in code&design, some people still don't know how to use oversea services.

Most of the hackathons in China don't have the enough revenue to run. They seldom have support from Big Tech like Tencent, Alibaba, Baidu or ByteDance, except for those launched by Big Tech. So there is far less hackathons here in China, and is reasonable why the hackathons in China is poor and low-quality: it just hard to launch new one.

Hasty is evil

Maybe this is not a special one in China, the hackathon oversea is also. But I still wanna say: lots of people are hasty here.

When I join in AdventureX 2025, you could hear at least five people here are drop out, or just don't care school work, just for join hackahton or embrace innovation. Everyone seems want to be next Elon, Jobs, Gates, want to build something great, but hardly sit for a single thing to do.

Enter your email to subscribe to updates.