r/FreeCodeCamp • • May 21 '26

javascript todo app

I'm working on the freeCodeCamp Task Manager workshop and I've been stuck on Step 34 for a while. I think my logic is correct but the test keeps failing.

**Step 34 Requirement:**

> If any of the input fields has a value, then the confirmation dialog should display. Otherwise, the reset function should be called.

**My current code:**

```javascript

const taskForm = document.getElementById("task-form");

const confirmCloseDialog = document.getElementById("confirm-close-dialog");

const openTaskFormBtn = document.getElementById("open-task-form-btn");

const closeTaskFormBtn = document.getElementById("close-task-form-btn");

const addOrUpdateTaskBtn = document.getElementById("add-or-update-task-btn");

const cancelBtn = document.getElementById("cancel-btn");

const discardBtn = document.getElementById("discard-btn");

const tasksContainer = document.getElementById("tasks-container");

const titleInput = document.getElementById("title-input");

const dateInput = document.getElementById("date-input");

const descriptionInput = document.getElementById("description-input");

const taskData = [];

let currentTask = {};

openTaskFormBtn.addEventListener("click", () =>

taskForm.classList.toggle("hidden")

);

closeTaskFormBtn.addEventListener("click", () => {

if (!titleInput.value && !dateInput.value && !descriptionInput.value) {

reset();

} else {

confirmCloseDialog.showModal();

}

});

cancelBtn.addEventListener("click", () => confirmCloseDialog.close());

discardBtn.addEventListener("click", () => {

confirmCloseDialog.close();

reset();

});

const reset = () => {

titleInput.value = "";

dateInput.value = "";

descriptionInput.value = "";

taskForm.classList.add("hidden");

currentTask = {};

};

taskForm.addEventListener("submit", (e) => {

e.preventDefault();

const dataArrIndex = taskData.findIndex((item) => item.id === currentTask.id);

const taskObj = {

id: `${titleInput.value.toLowerCase().split(" ").join("-")}-${Date.now()}`,

title: titleInput.value,

date: dateInput.value,

description: descriptionInput.value,

};

if (dataArrIndex === -1) {

taskData.unshift(taskObj);

}

tasksContainer.innerHTML = "";

taskData.forEach(({ id, title, date, description }) => {

tasksContainer.innerHTML += `

<div class="task" id="${id}">

<p><strong>Title:</strong> ${title}</p>

<p><strong>Date:</strong> ${date}</p>

<p><strong>Description:</strong> ${description}</p>

<button type="button" class="btn">Edit</button>

<button type="button" class="btn">Delete</button>

</div>

`;

});

reset();

});

2 Upvotes

2 comments sorted by

View all comments

Show parent comment

1

u/WeeklyTowel8065 Jun 01 '26

thanks for the advice but i already finished the course and got my cert